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

当前回答

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

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

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

其他回答

好吧,我今天在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声卡,这真的不应该引起这个问题,除了我之外没有其他人使用过这个系统。如果有人有线索,请评论以防止我和其他遇到这种情况的人。

通常,连接脚本不会提到要使用的端口。例如:

$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database');

所以,要连接到一个不使用端口3306的管理器,你必须在连接请求上指定端口号:

$mysqli = mysqli_connect('127.0.0.0.1', 'user', 'password', 'database', '3307');

要检查MySQL或MariaDB数据库管理器上的连接,使用脚本: 里面(64)\ www \ testmysql.php 在浏览器地址栏中输入“http://localhost/testmysql.php”,然后根据参数修改脚本。

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

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

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

启用“编辑并继续”

这是非常具体的,但是如果你在尝试使用mongo连接到数据库后收到这个错误,对我来说,在运行mongo.exe之前运行mongo.exe,然后连接工作正常。希望这能帮助到一些人。