Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
in my C# project, I added a web reference from the internet. It was added correctly.
But when I call the web service's functions, it will crash! with this error exception:
The remote server returned an unexpected response: (407) Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  ).


I changed the 'LAN settings' in Internet Options, and Unchecked the boxes 'Use automatic configuration script' and 'Use a proxy server for your LAN' .
It would have this error exception:
There was no endpoint listening at http:// ... 
Posted
Updated 24-May-22 22:49pm
v3

If above doesn't work and want to handle proxy in code

If you're using HttpClient then consider this.
C#
HttpClientHandler handler = new HttpClientHandler();
    
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
handler.Proxy = proxy;

var client = new HttpClient(handler);
// your next steps...

And if you're using HttpWebRequest:
C#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri + _endpoint);
    
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
request.Proxy = proxy;


Kind referencce: https://medium.com/@siriphonnot/the-remote-server-returned-an-error-407-proxy-authentication-required-86ae489e401b
 
Share this answer
 
Comments
Richard MacCutchan 27-Jun-20 5:33am    
As you can see the questioner solved his problem five years ago.
My problem was solved by writing this code in app.config of my c# project, into configuration tag:
<system.net>
  <defaultproxy usedefaultcredentials="true" />
</system.net>
 
Share this answer
 
The CredentialCache method above (Solution 2) did not work for me (maybe a different authentication type?).

The useedfaultcredentials method (Solution 1) did work and can be implemented in code thus:

HttpWebRequest request = WebRequest.CreateHttp(uri)

WebProxy proxy = new WebProxy();
proxy.UseDefaultCredentials = true;
request.Proxy = proxy;


Documentation : WebProxy.UseDefaultCredentials

Hope that helps someone out - I couldn't find it mentioned anywhere in these sort of questions.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900