Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebProxy error: Proxy Authentication Required

I use the following code to obtaing html data from the internet:

WebProxy p = new WebProxy("localproxyIP:8080", true);
p.Credentials = new NetworkCredential("domain\\user", "password");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.google.com");

But the following error is appeared: "Proxy Authentication Required". I can't use default proxy because of my code runs from windows service under the special account which there is no default proxy settings for. So, I want to specidy all proxy settings in my code. Please advice me how to resolve this error.

like image 385
Oleg Ignatov Avatar asked Oct 22 '12 09:10

Oleg Ignatov


People also ask

What is a proxy authentication required?

What Does “407 Proxy Authentication Required” Mean? The “407 Proxy Authentication Required” error occurs when the server is unable to complete a request. This happens due to a lack of authentication credentials when a proxy server is used between the client and server.

How do I fix error 407 in Chrome?

This error is related to proxy authentication. To view or change your proxy settings in Google Ads Editor, select Tools > Settings (Windows) or Google Ads Editor > Preferences (Mac). Was this helpful?

Does a reverse proxy provide authentication?

In addition to protecting MobileFirst resources from the Internet, the reverse proxy provides termination of HTTPS (SSL) connections and authentication.


3 Answers

This worked for me:

IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
client = new WebClient
    {
        Proxy = defaultWebProxy
    };
string downloadString = client.DownloadString(...);
like image 110
Johan Larsson Avatar answered Oct 23 '22 02:10

Johan Larsson


You've to set the WebClient.Proxy Property..

WebProxy p = new WebProxy("localproxyIP:8080", true);
p.Credentials = new NetworkCredential("domain\\user", "password");
WebRequest.DefaultWebProxy = p;
WebClient client = new WebClient();
**client.Proxy = p;**
string downloadString = client.DownloadString("http://www.google.com");
like image 36
2GDev Avatar answered Oct 23 '22 00:10

2GDev


Try this code

var transferProxy = new WebProxy("localproxyIP:8080", true);
transferProxy.Credentials = new NetworkCredential("user", "password", "domain");
var transferRequest = WebRequest.Create("http://www.google.com");
transferRequest.Proxy = transferProxy;
HttpWebResponse transferResponse = 
    (HttpWebResponse)transferRequest.GetResponse(); 
System.IO.Stream outputStream = transferResponse.GetResponseStream();
like image 1
Marco Avatar answered Oct 23 '22 00:10

Marco