无法解析远程名称 - webclient

k-s*_*k-s 9 c# asp.net webclient

我正面临这个错误:

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");
Run Code Online (Sandbox Code Playgroud)

当我在我的本地代码/环境中放置相同的URL时,它工作正常.

Yur*_*ter 7

很可能您运行代码的其他位置确实无法访问该远程位置.即在许多企业环境服务器中不允许外部Internet访问.你可能想尝试russgates85-001-site1.smarterasp.net 其他服务器ping/traceroute ,如果没有访问权限 - 配置路由器/防火墙(开放端口等)或使用代理

  • 不,你不明白。即使对于远程部署的站点,在代码中(而不是在浏览器地址栏中)也将URL作为“ localhost”使用-在这种情况下,它将代替“ russgate ...”使用 (2认同)

小智 5

我碰到了这个并且需要使用远程服务器的IP而不是DNS名称.Production试图使用其DNS名称访问远程服务器,这在防火墙的那一侧是不可行的.