Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

407 Proxy Authentication Required

Tags:

asp.net

proxy

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

like image 476
Hemant Kothiyal Avatar asked Dec 13 '22 02:12

Hemant Kothiyal


2 Answers

@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

like image 125
PeterA Avatar answered Dec 27 '22 13:12

PeterA


It might be helpful for someone out there finding this via Google that you can actually put this to use in .NET applications that may not have their own AppName.exe.config file yet (or you can modify it if so). We use NextGen EPM (medical scheduling / billing) and their credit-card processing system kept getting stuck at our proxy server because it wouldn't pass the credentials. I made an EXEName.config file (NextGenEPM.exe.config in this case) containing the snippet above:

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

Success! This allowed me to resolve the issue without mucking around in our proxy server, which is adamantly configured to require authentication and we'd rather not compromise that.

like image 23
user42600 Avatar answered Dec 27 '22 12:12

user42600