The remote name could not be resolved - webclient

浪子不回头ぞ 提交于 2019-12-21 09:06:16

问题


I am facing this error :

The remote name could not be resolved: 'russgates85-001-site1.smarterasp.net'

When I request html contents to read using web client it gives me error. Below is my code.

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");

When I put the same URL on my local code/environment it works fine.


回答1:


Most likely the other location you run the code on indeed does not have access to that remote location. I.e. in many corporate environment servers aren't allowed outside Internet access. You may want to try to ping/traceroute russgates85-001-site1.smarterasp.net from that other server and if there's no access - configure router/firewall (open port etc.) or use proxy




回答2:


I ran into this and needed to use the IP of the remote server rather than the DNS name. Production was trying to access the remote server using its DNS name, which was not viable on that side of the firewall.




回答3:


I had the same issue and got it resolved by setting the Proxy for the webclient

explicitly like

 webClient.Proxy = new WebProxy("myproxy.com:portnumber"); 
 byte[]  bytearr= webClient.DownloadData(acsMetadataEndpointUrlWithRealm);



回答4:


By default it will take system proxy.

To solve this, force to set your proxy in web.config or .cs api webclient.

Code fix should be like following, In under System.net section in web.config

<defaultProxy>

<proxy proxyaddress="http://0.000.000.000:00" bypassonlocal="True" usesystemdefault="False" autoDetect="False" />

</defaultProxy>


来源:https://stackoverflow.com/questions/16626348/the-remote-name-could-not-be-resolved-webclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!