底层连接被关闭:连接被意外关闭
我在使用 WebClient 时收到错误消息。我已经用 asp 代码对此进行了测试,它运行得很好。但是当我尝试运行exe版本的代码时,它运行以下错误,并且我能够从服务器访问请求地址,并且它在内部网络内。
我的服务器设置:- Windows Server 2003 Entrerprise SP2 asp.net 2.0.50727 iis v6.0
这是一些代码:
手动访问
protected static String cross_server_req(String strContent, String strPage, String strPrivateKey)
{
try
{
WebClient wc = new WebClient();
String strURL = SERVICE_PATH + strPage + "?r=" + DES_.DESEncrypt(strContent);
byte[] responseArray = wc.DownloadData(strURL);
String strResData = Encoding.UTF8.GetString(responseArray);
if (Config.RecordWebService == "1")
{
String strLogContent = "Request:" + strContent + "\r\nResponse:" + strResData + "\r\nDateCreated:" + D_Time.DNow + "\r\n\r\n";
ServiceLog.Logger(strPage, strLogContent);
}
if (null != strResData && String.Empty != strResData)
{
return strResData.Trim();
}
}
catch (Exception ex)
{
ServiceLog.Logger("cross_server_req() Exception:" + ex.Message + "\r\n" + ex.StackTrace);
}
return null;
}
这是来自日志
cross_server_req() Exception:The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadData(Uri address)
at System.Net.WebClient.DownloadData(String address)
at Account.cross_server_request_curl(String strContent, String strPage, String strPrivateKey)
请让我知道有什么建议可以帮助解决这个问题吗?我环顾了该站点,但没有找到解决方案。