有时我在做WebService的HttpWebRequest的时候遇到下面的错误。 我也复制了下面的代码。 System.Net.WebException:无法连接到远程服务器—> System.Net.Sockets.SocketException:无法build立连接,因为目标机器主动拒绝它127.0.0.1:80 在System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress) 在System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) 在System.Net.ServicePoint.ConnectSocketInternal(布尔connectFailure,套接字s4,套接字s6,套接字和套接字,IP地址和地址,ConnectSocketState状态,IAsyncResult asyncResult,Int32超时,exception和例外) —内部exception堆栈跟踪结束— 在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 […]