WebProxy error: Proxy Authentication Required
37,595
Solution 1
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");
Solution 2
This worked for me:
IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
client = new WebClient
{
Proxy = defaultWebProxy
};
string downloadString = client.DownloadString(...);
Solution 3
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();
Related videos on Youtube
Author by
Oleg Ignatov
Updated on July 12, 2022Comments
-
Oleg Ignatov almost 2 years
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.
-
jwaliszkotry to remove the domain\\ part (also remember of wrapping
WebClient
withusing()
statement because it implementsIDisposable
)
-
-
jwaliszko over 11 yearsit's not needed because
WebRequest.DefaultWebProxy = p
is enough -
2GDev over 11 yearsyou're right if you use WebRequest.Create() and after you call WebRequest.GetResponse(). But in this case he's using the WebClient to make request so the Proxy is not the same.
-
jwaliszko over 11 yearsActually
DownloadString
method internally usesWebRequest
object created byWebRequest.Create()
. If proxy wasn't particularly set toWebClient
object, suchWebRequest
object uses proxy obtained fromWebRequest.InternalDefaultWebProxy
property, which is just set byWebRequest.DefaultWebProxy = p
statement; -
Brad Bruce almost 11 yearsWonderful! This should be part of every WebClient sample.
-
Peska over 6 yearsImho solution below stackoverflow.com/a/17187136/7225096 is better.
-
amartin94 almost 6 yearsCan confirm this answer is perfect - We distributed software to clients that kept hitting this issue due to network restrictions. This patched the single issue everyone was facing. This should be the selected answer. YOU SAVED ME
-
KevinBui almost 4 yearsI use Console dotnet Core, how can i config it in setting file (such as app.config in Net Framework)