有时我得到以下错误,当我做HttpWebRequest到一个WebService。我也复制了下面的代码。


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();

当前回答

我遇到了这个错误,花了一些时间来解决它。在我的情况下,我有https和net。tcp配置为相同端口上的IIS绑定。显然,你不能在同一个端口上有两个东西。我使用netstat -ap tcp命令检查该端口上是否有侦听。没有人在听。删除不必要的绑定(在我的情况下是https)解决了我的问题。

其他回答

在我的例子中,有些域名可以使用,而有些则不行。在我的网页中添加对我的组织的代理Url的引用。配置修复了这个问题。

<system.net>
    <defaultProxy useDefaultCredentials="true">
      <proxy proxyaddress="http://proxy.my-org.com/" usesystemdefault="True"/>
    </defaultProxy>
</system.net>

我经常遇到这种问题。我发现SQL Server代理服务没有运行。当我手动启动这项服务时,问题就解决了。再次检查服务是否在运行:

运行提示符,输入services。MSC,然后回车 查找服务名称- SQL Server代理(实例名)

如果SQL Server Agent未运行,双击该服务打开属性窗口。然后点击开始按钮。希望它能帮助到一些人。

在Windows 7 Home Premium 64bit上使用WampServer 64bit时,我遇到了这个确切的问题。经过一小时又一小时的试验,很明显,我们所需要的只是在my.ini中注释掉一行。然后它工作得很好。

注释掉1行 套接字= mysql

如果你把旧的/data/文件放在合适的位置,WampServer将接受所有这些文件,除了它要重写的/mysql/文件夹。因此,然后我简单地从我以前的开发环境中导入/mysql/ user数据的备份,并在phpMyAdmin SQL窗口中运行FLUSH PRIVILEGES。伟大的工作。一定是出了什么问题,因为事情不应该这么容易。

转到你的WCF项目- 属性- > -> 调试器 ->取消复选框的标记

启用“编辑并继续”

我还建议检查http_proxy环境变量。

https://www.golinuxcloud.com/set-up-proxy-http-proxy-environment-variable/: ~:文本= % 20 http_proxy % 20和% 20 https_proxy % 20的环境,等% 20 % 20卷% 20和% 20 wget % 20。