Remote name could not be resolved - webclient

I ran into this error:

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

When I request html content to be read using the web client, it gives me an 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 in my local code / environment, it works fine.

+9
source share
4 answers

Most likely, the other place where you run the code does not really have access to this remote location. That is, on many servers of the corporate environment access via the Internet is not allowed. You can try ping / traceroute russgates85-001-site1.smarterasp.net from this other server, and if you don’t have access, configure a router / firewall (open port, etc.) Or use a proxy

+7
source

I came across this and had to use the IP of the remote server, not the DNS name. The products tried to access the remote server using their DNS name, which was not viable on this side of the firewall.

+5
source

I had the same problem and I decided to solve it by installing proxies for the web client

clearly like

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

By default, this will take the system proxy.

To solve this problem, install your proxy in web.config or .cs api webclient.

The code fix should be something like the one in the System.net section of web.config

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

Source: https://habr.com/ru/post/945331/


All Articles