C# 无法解析远程名称 - webclient

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16626348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:30:39  来源:igfitidea点击:

The remote name could not be resolved - webclient

c#asp.netwebclient

提问by k-s

I am facing this error :

我正面临这个错误:

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

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.

当我请求使用 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");

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

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

采纳答案by Yuriy Galanter

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.netfromthat other server and if there's no access - configure router/firewall (open port etc.) or use proxy

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

回答by Ken Johnson

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.

我遇到了这个问题,需要使用远程服务器的 IP 而不是 DNS 名称。生产尝试使用其 DNS 名称访问远程服务器,这在防火墙的那一侧是不可行的。

回答by Sundara Prabu

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

我遇到了同样的问题,并通过为 webclient 设置代理来解决它

explicitly like

明确喜欢

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

回答by Kamarajan Chandran

By default it will take system proxy.

默认情况下,它将采用系统代理。

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

要解决此问题,请强制在 web.config 或 .cs api webclient 中设置您的代理。

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

代码修复应如下所示,在 web.config 的 System.net 部分下

<defaultProxy>

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

</defaultProxy>