【发布时间】:2013-05-13 15:26:23
【问题描述】:
我正面临这个错误:
The remote name could not be resolved: 'russgates85-001-site1.smarterasp.net'
当我请求使用 Web 客户端读取 html 内容时,它给了我错误。 下面是我的代码。
string strHTML = string.Empty;
WebClient myClient = new WebClient();
UTF8Encoding utf8 = new UTF8Encoding();
byte[] requestHTML;
string pdfFileName = "outputpdf_" + DateTime.Now.Ticks + ".pdf";
string webUrl = Request.Url.Scheme + "://" + Request.Url.Host + (Request.Url.Port != 80 ? ":" + Request.Url.Port : "");
requestHTML = myClient.DownloadData("http://russgates85-001-site1.smarterasp.net/adminsec/images/printinvoice.aspx?iid=2");
// OR
requestHTML = myClient.DownloadData(webUrl + "?iid=3");
当我将相同的 URL 放在本地代码/环境中时,它可以正常工作。
【问题讨论】:
-
您运行 ASP.NET 代码的 Web 服务器是否也是您的本地开发机器或其他机器?
-
仅供参考,如果您向在 https 下运行的没有有效证书的站点发出请求,您也可以获得此信息。 (即 IIS Express 开发证书)。在浏览器中点击它并接受警告插页式将允许它加载。
-
Ken Johnson said 需要使用服务器 IP 而不是服务器名称。