底层连接已关闭:接收时发生意外错误。 [英] The underlying connection was closed: An unexpected error occurred on a receive.

查看:128
本文介绍了底层连接已关闭:接收时发生意外错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我再次发布同样的问题。因为我没有得到我之前的问题的任何答复。

我正在处理一个应用程序。它是一个在.net 2.0中开发的窗口应用程序



现在的问题是,当我运行我的应用程序并向另一个应用程序发送请求时,它成功发送但我得到问题时,我收到响应它告诉我错误和错误是



基础连接已关闭:接收时发生意外错误。 />


这是我的代码



Hello everyone

I am posting the same question again. Because i did not get any reply from my previous question.
I am working on an application. Its a window application which developed in .net 2.0

Now the problem is this that when ever i run my application and i send a request to another application its send successfully but i get the problem when i get the response its show me the error and the error is

The underlying connection was closed: An unexpected error occurred on a receive.

here is my code

public string tm4b(string sURL, bool bEscapeURL, string sPostData)
{
sURL = sURL.Trim();
while (sURL.IndexOf(" ") > 0)
{
sURL = sURL.Replace(" ", " ");
}
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string stmp = string.Empty;
Uri httpUri = new Uri(sURL, bEscapeURL);
try
{
 
System.Text.ASCIIEncoding byteConverter = new System.Text.ASCIIEncoding();
byte[] byte1 = byteConverter.GetBytes(sPostData);
System.Net.HttpWebRequest hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(httpUri);
 
hwRequest.ContentType = "application/x-www-form-urlencoded";
hwRequest.Method = "POST";
 
hwRequest.ContentLength = sPostData.Length; ;
System.IO.Stream PostStream = hwRequest.GetRequestStream();
PostStream.Write(byte1, 0, byte1.Length);
System.Net.HttpWebResponse hwResponse = (System.Net.HttpWebResponse)hwRequest.GetResponse();
System.IO.StreamReader sRead = new System.IO.StreamReader(hwResponse.GetResponseStream(),
System.Text.Encoding.ASCII);
 
if ((stmp = sRead.ReadLine()) != null)
{
 
sb.Append(stmp + "");
 
}
 
PostStream.Close();
sRead.Close();
 
return sb.ToString();
 
}
catch (Exception ex)
{
 
return "error";
}
return "Request Error";
 
}







但它只给一个网址带来这个错误并为他人的网址运作良好



请检查代码和错误,请告诉我我必须做什么

i尝试了所有的逻辑我可以使用但没有得到任何好结果



所以专家请帮助我




But its give me this error for only one url and for anothers url its working well

Please check the code and error and please tell me what i have to do
i tried all the logics that i can use but did not get any good results

So experts please help me

推荐答案

但它只给了我一个网址的错误,而且其他网址的工作效果很好 - 这就是重点。它是哪个URL?从常用Web浏览器(例如Internet Explorer)使用URL时,URL是否有效?当服务器决定关闭连接时,您的客户端代码中会出现错误,这实际上是客户端的正确行为。如果服务器也是你的,请检查服务器对该URL的操作。
"But its give me this error for only one url and for anothers url its working well" - that's the important point. Which URL is it? Does the URL work when you use it from a common web browser (e.g. Internet Explorer)? When the server decides to close the connection, you'll get an error in your client code, and that is actually correct behavior of your client. If the server is also yours, check what the server is doing with that URL.


这与TLS有关,只需将.net升级到最新版本。



当服务器拒绝从服务器端禁用tlsv1.0或tlsv1.0时会发生这种情况。

要从客户端解决此问题,只需升级到最新版本版本和看。
This is related to TLS, Just upgrade the .net to the latest version.

This happens when the server denies tlsv1.0 or tlsv1.0 is disabled from the server side.
To resolve this from the client side just upgrade to the latest version and see.


我在运行应用程序的机器上使用fidler并在app config中添加此代码



< br $> b $ b

I use fidler on machine in which the application is running and add this code in app config



<system.net>
<settings>
<httpwebrequest useunsafeheaderparsing="true" />
</settings>
</system.net>







它正在工作但当我退出fidler然后它给我错误是什么原因请告诉我




Its working then but when i exit the fidler then its give me error what is the reason please tell me


这篇关于底层连接已关闭:接收时发生意外错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆