407 需要代理认证 [英] 407 Proxy Authentication Required

查看:28
本文介绍了407 需要代理认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个网站上工作,我正在使用以下代码从外部 URL 检索 XML 数据

I am working on a website, in which I am retrieving XML data from an external URL, using the following code

WebRequest req = WebRequest.Create("External server url");
req.Proxy = new System.Net.WebProxy("proxyUrl:8080", true);
req.Proxy.Credentials = CredentialCache.DefaultCredentials;
WebResponse resp = req.GetResponse();
StreamReader textReader = new StreamReader(resp.GetResponseStream());
XmlTextReader xmlReader = new XmlTextReader(textReader);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);

此代码在我的开发 PC(Windows XP 和 .Net 3.5)上运行良好

This code is working fine on my development PC (Windows XP with .Net 3.5)

但是当我将此代码部署到 IIS(在 Windows XP 和 Windows Server 2003 上)时,它给了我以下错误

But when I deploy this code to IIS (Both at Windows XP and at Windows Server 2003) it's giving me following error

远程服务器返回错误:(407) 需要代理身份验证."

"The remote server returned an error: (407) Proxy Authentication Required."

有时它给了我

远程服务器返回错误:(502) Bad Gateway."

"The remote server returned an error: (502) Bad Gateway."

以下代码来自我的 web.config

Following code is from my web.config

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

请帮帮我?

即使当我运行用于开发 PC 的网站但通过 IIS 时,它也会给我错误远程服务器返回错误:(407)需要代理身份验证."

Even when i run the website for devlopment PC but through IIS it gives me error "The remote server returned an error: (407) Proxy Authentication Required."

但是当我从 Microsoft Devlopment 服务器运行网站时,它运行良好

But when i run website from Microsoft Devlopment server, it is running fine

推荐答案

@Mohit Agarwal

@Mohit Agarwal

非常感谢您建议添加' useDefaultCredentials="true" ',您就是明星!

Many thanks for suggesting adding ' useDefaultCredentials="true" ', you're a star!

数周以来,我一直试图为 Google 数据 API 示例 exe 获取 .NET 库,但没有成功.添加您的建议解决了我的问题,我现在获得了连接而不是 407 代理身份验证.

I have been trying to get the .NET library for the Google Data API sample exe's working for weeks without success. Adding your suggestion fixed my problem and I now get a connection instead of 407 Proxy Authentication Required.

spreadsheet.exe.config 内容需为:

speadsheet.exe.config contents need to be:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.net>
    <defaultProxy useDefaultCredentials="true">
      <proxy usesystemdefault="true"/>
    </defaultProxy>
  </system.net>
</configuration>

就我而言,不像谷歌建议的那样:

In my case NOT as Google suggest:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <system.net>
  <defaultProxy>
   <proxy usesystemdefault="true"/>
  </defaultProxy>
 </system.net>
</configuration>

http://code.google.com/p/google-gdata/wiki/WebProxySetup

这篇关于407 需要代理认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆