No connection could be made because the target mac

2018-12-31 07:38发布

Sometimes I get the following error while I was doing HttpWebRequest to a WebService. I copied my code below too.


System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:80
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetRequestStream()

ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.PreAuthenticate = true;
request.Credentials = networkCredential(sla);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = v_Timeout * 1000;

if (url.IndexOf("asmx") > 0 && parStartIndex > 0)
{
    AppHelper.Logger.Append("#############" + sla.ServiceName);

    using (StreamWriter reqWriter = new StreamWriter(request.GetRequestStream()))
    {                        
        while (true)
        {
            int index01 = parList.Length;
            int index02 = parList.IndexOf("=");

            if (parList.IndexOf("&") > 0)
                index01 = parList.IndexOf("&");

            string parName = parList.Substring(0, index02);
            string parValue = parList.Substring(index02 + 1, index01 - index02 - 1);

            reqWriter.Write("{0}={1}", HttpUtility.UrlEncode(parName), HttpUtility.UrlEncode(parValue));

             if (index01 == parList.Length)
                 break;

             reqWriter.Write("&");
             parList = parList.Substring(index01 + 1);
         }
     }
 }
 else
 {
     request.ContentLength = 0;
 }

 response = (HttpWebResponse)request.GetResponse();

23条回答
还给你的自由
2楼-- · 2018-12-31 08:16

I've received this error from referencing services located on a WCFHost from my web tier. What worked for me may not apply to everyone, but I'm leaving this answer for those whom it may. The port number for my WCFHost was randomly updated by IIS, I simply had to update the end routes to the svc references in my web config. Problem solved.

查看更多
无色无味的生活
3楼-- · 2018-12-31 08:17

I had the same problem. The problem is that I didn't start the selenium server. I have downloaded the selenium server and i started it. After starting the selenium server, issue gone and all worked fine.

Refer this : http://coding-issues.blogspot.in/2012/11/no-connection-could-be-made-because.html

查看更多
无色无味的生活
4楼-- · 2018-12-31 08:17

Well, I've received this error today on Windows 8 64-bit out of the blue, for the first time, and it turns out my my.ini had been reset, and the bin/mysqld file had been deleted, among other items in the "Program Files/MySQL/MySQL Server 5.6" folder.

To fix it, I had to run the MySQL installer again, installing only the server, and copy a recent version of the my.ini file from "ProgramData/MySQL/MySQL Server 5.6", named my_2014-03-28T15-51-20.ini in my case (don't know how or why that got copied there so recently) back into "Program Files/MySQL/MySQL Server 5.6".

The only change to the system since MySQL worked was the installation of Native Instruments' Traktor 2 and a Traktor Audio 2 sound card, which really shouldn't have caused this problem, and no one else has used the system besides me. If anyone has a clue, it would be kind of you to comment to prevent this for me and anyone else who has encountered this.

查看更多
听够珍惜
5楼-- · 2018-12-31 08:19

This is really specific, but if you receive this error after trying to connect to a database using mongo, what worked for me was running mongod.exe before running mongo.exe and then the connection worked fine. Hope this helps someone.

查看更多
栀子花@的思念
6楼-- · 2018-12-31 08:19

I had the same error with my WCF service using Net TCP binding, but resolved after starting the below services in my case.

Net.Pipe.Listener.Adapter

Net.TCP.Listener.Adapter

Net.Tcp Port Sharing Service

查看更多
旧时光的记忆
7楼-- · 2018-12-31 08:21

For service reference within a solution.

  1. Restart your workstation

  2. Rebuild your solution

  3. Update service reference in WCFclient project

At this point, I received messsage (Windows 7) to allow system access. Then the service reference was updated properly without errors.

查看更多
登录 后发表回答