Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

asp.net - 407 Proxy Authentication Required

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

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

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

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

Sometimes it gives me

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

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> 

Please help me ?

[Edit] 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."

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@Mohit Agarwal

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

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...