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