有时我得到以下错误,当我做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();

当前回答

我也有同样的问题。问题是我没有启动硒服务器。我已经下载了硒服务器,并启动了它。启动硒服务器后,问题消失了,一切正常工作。

参考这个:http://coding-issues.blogspot.in/2012/11/no-connection-could-be-made-because.html

其他回答

好吧,我今天在64位的Windows 8上突然收到了这个错误,这是第一次,原来我的my.ini被重置了,bin/mysqld文件被删除了,以及“Program Files/MySQL/MySQL Server 5.6”文件夹中的其他项目。

为了解决这个问题,我不得不再次运行MySQL安装程序,只安装服务器,并从“ProgramData/MySQL/MySQL server 5.6”中复制my.ini文件的最新版本,在我的情况下命名为my_2014-03-28T15-51-20.ini(不知道为什么最近会复制到那里)回到“Program Files/MySQL/MySQL server 5.6”中。

自从MySQL工作以来,系统唯一的变化是安装了Native Instruments的Traktor 2和Traktor Audio 2声卡,这真的不应该引起这个问题,除了我之外没有其他人使用过这个系统。如果有人有线索,请评论以防止我和其他遇到这种情况的人。

我在一个使用AppFabric的应用程序中得到了这个错误。线索是在堆栈跟踪中获得一个DataCacheException。要查看这是否是您的问题,请运行以下PowerShell命令:

@("AppFabricCachingService","RemoteRegistry") | % { get-service $_ }

如果这两个服务中的任何一个停止了,那么您将得到这个错误。

在我的情况下,这是由一个错误的部署,在我的网络设置。没有配置。

一位同事解释说,错误消息中的IP地址代表本地主机。

当我修正网页的时候。我当时使用正确的url进行服务器调用,它工作。

我想我应该把这个贴出来,也许能帮助到一些人。

I was facing this issue today. Mine was Asp.Net Core API and it uses Postgresql as the database. We have configured this database as a Docker container. So the first step I did was to check whether I am able to access the database or not. To do that I searched for PgAdmin in the start as I have configured the same. Clicking on the resulted application will redirect you to the http://127.0.0.1:23722/browser/. There you can try access your database on the left menu. For me I was getting an error as in the below image.

输入密码,并尝试是否能够访问它。对我来说,这行不通。因为它是一个Docker容器,我决定重新启动我的Docker桌面,右键单击任务栏中的Docker图标,然后单击重新启动。

在重新启动Docker后,我能够登录并看到数据库,并且当我在Visual Studio中重新启动应用程序时,错误也消失了。

希望能有所帮助。

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

注释掉1行 套接字= mysql

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