收到“无法解析远程服务器”在本地主机上默认代理没有得到修复?

发布于 2024-08-12 15:08:11 字数 550 浏览 1 评论 0原文

情况是这样的,我正在家里的机器上在本地主机上进行测试(没有代理服务器和 Windows 默认防火墙)并检索 api.flickr.com xml 文件,当我上班时(使用 ISA 服务器进行连接)我得到“远程服务器无法解析”,因此我将这些行添加到

<system.net>
  <defaultProxy>
   <proxy
    usesystemdefault="False"
    proxyaddress="http://localhost"
    bypassonlocal="True"
     />
   <bypasslist>
    <add address="[a-z]+\.flickr\.com\.+" />
   </bypasslist>

  </defaultProxy>
 </system.net>

返回的 web.config 中:System.Net.WebException:远程服务器返回错误:(404) 未找到。 出了什么问题?谢谢

here is the sitution, i am testing on my localhost from my machine at home (no proxy server and windows default firewall) and retrieving api.flickr.com xml file, when I come to work (that uses an ISA server to connect) I get "remote server could not be resolved" so I added these lines to the web.config

<system.net>
  <defaultProxy>
   <proxy
    usesystemdefault="False"
    proxyaddress="http://localhost"
    bypassonlocal="True"
     />
   <bypasslist>
    <add address="[a-z]+\.flickr\.com\.+" />
   </bypasslist>

  </defaultProxy>
 </system.net>

that returns:System.Net.WebException: The remote server returned an error: (404) Not Found.
what went wrong? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无力看清 2024-08-19 15:08:11

这里有两种可能的情况:

1:如果您正在构建客户端应用程序(例如 Console 或 WinForms)并且想要访问 http://localhost< /a> 使用 WebClient 或 HttpWebRequest 而无需任何中间代理,则 bypassonlocal="True" 应该可以完成此操作。换句话说,您的 app.config 应如下所示:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

2:但是,如果您尝试获取 ASP.NET 应用程序(在 http://localhost)以便能够正确解析有代理或没有代理的 URI,那么您需要在 web.config(或 machine.config)中正确设置代理信息,以便您不必更改应用程序的 web.config),因此 ASP.NET 会知道您是否正在运行代理或未运行代理。像这样:

家庭:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

工作:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    proxyaddress="http://yourproxyserver:8080"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

也可以使用代理自动检测,从注册表中获取设置等,但我一直回避服务器应用程序的这些方法......太脆弱了。

顺便说一句,如果您发现配置正确,但仍然收到错误,我建议的第一件事是编写一个快速测试代码,在 WebClient/HttpWebRequest 调用之前手动设置代理,而不是依赖于配置做吧。像这样:

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebClient wc = new WebClient();
wc.Proxy = proxyObject;
string s = wc.DownloadString ("http://www.google.com");

如果即使您使用代码,请求也没有正确通过您的工作代理,即使代理在您的代码中正确配置,那么代理本身可能就是问题。

There are two possible scenarios here:

1: If you are building a client app (e.g. Console or WinForms) and want to access http://localhost using WebClient or HttpWebRequest without any intervening proxies, then bypassonlocal="True" should accomplish this. In other words, your app.config should look like this:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

2: if, however, you're trying to get your ASP.NET app (running on http://localhost) to be able to correctly resolve URIs either with a proxy or without one, then you'll need to set up proxy info correctly in your web.config (or in machine.config so you won't have to change your app's web.config), so ASP.NET will know that you are running a proxy or not running one. Like this:

Home:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

Work:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    proxyaddress="http://yourproxyserver:8080"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

It's also possible to use proxy auto-detection, to pick up settings from the registry, etc. but I've always shied away from those approaches for servers apps... too fragile.

BTW, if you find that things are configured correctly, and you still get the error, the first thing I'd recommend is to code up a quick test which manually sets the proxy before your WebClient/HttpWebRequest call, instead of relying on configuration to do it. Like this:

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebClient wc = new WebClient();
wc.Proxy = proxyObject;
string s = wc.DownloadString ("http://www.google.com");

If the requests don't go through your work proxy correctly even when you're using code, even if the proxy is correctly configured in your code, then the proxy itself may be the problem.

迷乱花海 2024-08-19 15:08:11

WebClient 中从本地下载数据没有问题,但从互联网下载数据有问题,因此请配置以下内容

在您的 Web.config 中添加以下行并替换您的 Intenet 代理地址端口

;
    
      >
    
    <设置>
      
     

现在您的程序逻辑可以从互联网和公共 URL 下载内容。

In WebClient to download data from local no issues but downloading from internet is problem so configure the following

In your Web.config add below lines and replace your Intenet proxy Address and port

<system.net>
    <defaultProxy useDefaultCredentials="true" enabled="true">
      <proxy usesystemdefault="False" proxyaddress="http://your proxy address:port" bypassonlocal="True" />
    </defaultProxy>
    <settings>
      <servicePointManager expect100Continue="false" />
    </settings>   </system.net>

now your program logic work for downloading content from internet and public URLS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文