标签: system.net.webexception

没有连接,因为目标机器主动拒绝它?

有时我在向WebService执行HttpWebRequest时遇到以下错误.我也复制了下面的代码.


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 = …
Run Code Online (Sandbox Code Playgroud)

.net c# socketexception system.net.webexception asp.net-web-api2

228
推荐指数
7
解决办法
103万
查看次数

服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF,在WinForms中?

我试图使用WebClient/HttpWebRequest从服务器下载一些数据.我使用以下代码来执行此操作:

WebClient client = new WebClient();
client.Credentials = new NetworkCredential("admin", "password");
Stream datastream = client.OpenRead("http://routerlogin.com/cgi-bin/CF_logs.html");
StreamReader reader = new StreamReader(datastream);
Run Code Online (Sandbox Code Playgroud)

服务器是我的页面在路由器的配置中.它可以在浏览器中正常工作,但是当使用我的代码下载时,它会抛出一条WebException消息

服务器提交了协议违规.Section = ResponseHeader Detail = CR必须后跟LF,在WinForms?中.

我找到了一个解决方案,如果他们使用ASP.net,可以使用,将以下内容添加到web.config:

<configuration> 
    <system.net> 
        <settings> 
            <httpWebRequest useUnsafeHeaderParsing="true" /> 
        </settings> 
    </system.net> 
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是,我正在制作一个WinForms应用程序,所以这对我不起作用.有什么替代方法可以解决这个问题?

c# webclient httpwebrequest system.net.webexception winforms

40
推荐指数
1
解决办法
5万
查看次数

System.Net.WebException:无法解析远程名称:

我正在测试一个端点,我遇到了一些问题.

我只是HttpClient在一个循环中使用,每小时执行一次请求.

var httpClient = new HttpClient();
var message = httpClient.GetAsync(url).Result;
Console.WriteLine(message.StatusCode);
Run Code Online (Sandbox Code Playgroud)

有一段时间我得到这个例外:

System.Net.Http.HttpRequestException:发送请求时发生错误.---> System.Net.WebException:无法解析远程名称:'xxx'

经验是在异常之后,可以访问URL.在浏览器中,您只需刷新页面即可.

我仍然没有得到用户体验它的任何报告,所以我想知道它是否只是一个本地问题,但可以使用一些信息来帮助诊断.

有没有办法检查无法解析远程名称是由DNS问题还是由例外的Web服务器问题引起的?我可以获得更多信息,HttpCLient还是需要更高级的诊断工具?

.net c# system.net.webexception

30
推荐指数
2
解决办法
11万
查看次数

通过SSL发送带有HttpWebRequest的请求时出现错误502(错误网关)

我在经典ASP中有以下代码段,用于发送命令并通过SSL检索响应:

Dim xmlHTTP
Set xmlHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
xmlHTTP.open "POST", "https://www.example.com", False
xmlHTTP.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
xmlHTTP.setRequestHeader "Content-Length", Len(postData)
xmlHTTP.Send postData
If xmlHTTP.status = 200 And Len(message) > 0 And Not Err Then
   Print xmlHTTP.responseText
End If
Run Code Online (Sandbox Code Playgroud)

然后我使用此代码作为参考,在c#中重新实现请求:

private static string SendRequest(string url, string postdata)
{
   WebRequest rqst = HttpWebRequest.Create(url);
   // We have a proxy on the domain, so authentication is required.
   WebProxy proxy = new WebProxy("myproxy.mydomain.com", 8080);
   proxy.Credentials = new NetworkCredential("username", "password", "mydomain");
   rqst.Proxy = proxy;
   rqst.Method = "POST";
   if …
Run Code Online (Sandbox Code Playgroud)

c# ssl httpwebrequest system.net.webexception

24
推荐指数
2
解决办法
9万
查看次数

HttpWebrequest失败,内部异常验证失败,因为远程方已关闭传输流

使用C#,.Net 4.5,我试图通过远程服务器上的HttpWebRequest发送Web请求.请参阅下面的代码.我尝试了一些论坛建议的大多数解决方案,但我总是遇到同样的错误.请参阅下面的堆栈跟踪.调用request.GetReponse()方法时抛出错误.

其他信息,基本上,我正在尝试调用安装在远程服务器上的vmware的vCenter组件的reloadSslCertificate功能.目前,该错误仅发生在vCenter 5.5上.它在5.1及以下版本中工作正常.

        var uri = String.Format("https://{0}/some_url", serverName);
        var request = (HttpWebRequest)WebRequest.Create(uri);
        request.KeepAlive = true;
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8");
        request.Credentials = credential;
        request.CookieContainer = cookieContainer;


        var response = request.GetResponse();
Run Code Online (Sandbox Code Playgroud)

异常:System.Net.WebException:基础连接已关闭:发送时发生意外错误.---> System.IO.IOException:身份验证失败,因为远程方已关闭传输流.System.Net.Security.SslState的System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)处于System.Net.Security.SslState的System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest). System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,Byte [] buffer,AsyncProtocolRequest)上的System.Net.Security.SslState.StartSendBlob(Byte []传入,Int32计数,AsyncProtocolRequest asyncRequest)中的CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest) System.Net.Security.SslState上的asyncRequest).

提前致谢.

c# vmware ssl-certificate system.net.webexception vcenter

24
推荐指数
2
解决办法
3万
查看次数

WCF方法调用两次

我有一个Web服务,它将数据返回到桌面应用程序.我遇到的问题是,当Web服务返回少量数据时,一切正常,但是当数据量很大时,它会抛出以下异常:

System.Net.WebException:基础连接已关闭:接收时发生意外错误.

当我调试Web服务时,我看到这个特殊的方法被调用了两次.它在第一次没有任何反应时执行return语句,但是当它第二次执行它时,桌面应用程序中会抛出上述异常.

我在stackoverflow之前发现了类似的帖子,但他们没有解决我的问题.有人可以告诉我这里发生了什么吗?

谢谢!

wcf web-services system.net.webexception

15
推荐指数
3
解决办法
7472
查看次数

操作之间的差异有超时和(504)网关超时

HttpWebRequest在我的应用程序中使用,它检查多个线程中的一些URI.我得到了多种类型的超时异常.

  • 操作已超时
  • 远程服务器返回错误:(504)网关超时.

他们的细节如下:

System.Net.WebException:操作已在System.Net.HttpWebRequest.GetResponse()处于超时时间......

System.Net.WebException:远程服务器返回错误:(504)Gateway Timeout.在System.Net.HttpWebRequest.GetResponse()at ....

这两者之间有什么不同.

我的功能如下:

public bool CheckUri(Uri m_url)
{
    try
    {
        HttpWebRequest request = HttpWebRequest.Create(m_url) as HttpWebRequest;
        request.UserAgent = "MyUserAgent";

        //For: The underlying connection was closed: An unexpected error occurred on a receive.
        request.KeepAlive = false; 
        request.ProtocolVersion = HttpVersion.Version10;

        request.Method = "HEAD"; //Get only the header information 
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            int statusCode = (int)response.StatusCode;
            if (statusCode >= 100 && statusCode < 400) //Good requests
            {
                string …
Run Code Online (Sandbox Code Playgroud)

.net c# system.net.webexception

15
推荐指数
2
解决办法
3万
查看次数

C#System.Net.WebException:底层连接已关闭:发送时发生意外错误

我只在一台运行Windows Server 2003的服务器上收到此错误:

System.Net.WebException:基础连接已关闭:发送时发生意外错误.


这是我的代码......有什么想法吗?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https:// URL HERE ");
//request.Headers.Add("Accept", "application/xml");
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(xml);
request.KeepAlive = false;
request.Accept = "application/xml";
request.ContentType = "application/xml; charset='UTF-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
request.Timeout = 10000;
request.ServicePoint.Expect100Continue = false;
Run Code Online (Sandbox Code Playgroud)

c# windows-server-2003 system.net.webexception

15
推荐指数
3
解决办法
8万
查看次数

读取WebException的响应流时出现WebException

我正在与.Net的网络服务器进行通信.Web服务器抛出500内部服务器错误并写入详细的错误消息.

我正在尝试读取从Web异常接收的错误消息,但获取另一个Web异常.为什么抛出第二个WebException?

try
{
  var webResponse = (HttpWebResponse)webRequest.GetResponse();
}
catch (WebException e)
{
  if (e.Status == WebExceptionStatus.ProtocolError)
  {
    // the next line throws a web exception
    Console.WriteLine(new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
  }
}
Run Code Online (Sandbox Code Playgroud)

.net http httpwebrequest system.net.webexception

14
推荐指数
1
解决办法
1万
查看次数

System.Net.WebException:请求已中止:请求已取消

我有一个WCF服务,在负载条件下给我这个错误(我似乎无法重新创建错误).我们一直试图找到解决方法大约一个星期,现在没有这样的运气..

我看到的错误有两个部分,

System.ServiceModel.CommunicationException:通过http通道传输数据时发生错误:(请求已中止:请求已取消.)

和:

System.Net.WebException:请求已中止:请求已取消.

我见过很多人建议通过重载Reference.cs文件和设置中的方法来禁用处于保持活动状态KeepAlive = false,但是,我们的客户端正在使用服务引用(除了Web引用)并且此选项不再存在.

我看到的另一个选项是向服务添加自定义绑定而不是BasicHttpBinding我们现在使用的,但是这会对那些使用webReference的人(因为CustomBinding没有启用SOAP)的后端支持Web服务.

有没有人以前处理过这个错误?有没有办法在不影响服务器端的情况下禁用WCF中的keep alive?是否还有其他任何可以导致此错误的活着?

.net wcf service-reference system.net.webexception communicationexception

14
推荐指数
2
解决办法
3万
查看次数