【发布时间】:2014-05-31 03:48:44
【问题描述】:
当我尝试使用 WebClient 访问单独的 asp 页面以从邮政编码下载完整的地址详细信息时,我不断收到错误消息。
The underlying connection was closed: An unexpected error occurred on a send.
这只发生在服务器上。不仅如此,当我将 URL 粘贴到浏览器中时,它可以完美运行。这可能是防火墙设置吗?
这是我正在使用的代码(取自 here 上的另一篇帖子)
using (CookieAwareWebClient WC = new CookieAwareWebClient())
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
string data = WC.DownloadString("https://www.myUrl.com/postcode.asp?postcode=" + postcode + "&houseNumber=" + Server.HtmlEncode(txtHouseNumber.Text));
}
原来我只是用这个,结果一样:
WebClient client = new WebClient();
string address = "https://www.myUrl.com/postcode.asp?postcode=" + postcode + "&houseNumber=" + Server.HtmlEncode(txtHouseNumber.Text);
string data = client.DownloadString(address);
该应用程序是使用 .NET 4/C# 构建的,并托管在带有 iis6 的 Windows Server 2003 上。
如果这是防火墙或安全设置,会是什么?如果没有,关于原因或解决方法的任何想法?非常感谢
更新 - ########################
好的,我也尝试过使用 HttpWebRequest,但第二行出现错误:
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(new Uri("https://www.myUrl.com/postcode.asp?postcode=AZ11ZA&houseNumber=1"));
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
错误信息包含:
System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at MyApp.MyPage.WebClientTest()
不知道对大家有没有帮助...
【问题讨论】:
-
您可以通过网络浏览器访问网址吗?
-
应用程序是用 .NET 构建的,但您请求的是 ASP 页面?
-
是的,URL 在浏览器中没有问题
-
@Cervesar - 是的,我知道这听起来很奇怪,但所有 asp 页面所做的都是使用邮政编码和门牌号访问外部服务并返回所有可能性的字符串。我也尝试使用包含我期望的信息的 .txt 文件,但结果相同。
-
您是否尝试过在 http 而不是 https 中访问它?