The remote server returned an error: (407) Proxy Authentication Re

R

Richard

My webcam app runs OK on XP but not on Vista. Here's my code snippet that
has been working up until now:

System.Net.WebRequest request;
System.Net.WebResponse response;
request = System.Net.FileWebRequest.Create(
"http://store.bearvalley.com/live/camimage_00001.jpg");
response = request.GetResponse();

When it tries to execute the request.GetResponse() call I get the following
exception:
The remote server returned an error: (407) Proxy Authentication Required.

I can paste the uri into my browser and it works OK.

Any assistance would be greatly appreciated.

Thanks! ;^)

Richard
 
N

Nicholas Paldino [.NET/C# MVP]

Richard,

You might want to change the code that calls the static Create method to
call off the WebRequest class. It won't fix your problem, but it makes the
code a little more accurate (considering that you are getting an
HttpWebRequest based on the URL).

The reason it works for you in your browser is because your browser is
set up correctly to use a proxy. You have to do the same thing in code,
creating an instance of the WebProxy class, setting the properties on it,
and then setting the Proxy property to that WebProxy instance.
 
R

Richard

Thanks Nicholas!
First I can't create an instance of WebRequest because the compiler gives an
error saying it's an abstract class - I don't know what that means but it
looks like I have to use the static Create method. So here's what I tried
based on your suggestion:

System.Net.WebRequest request;
System.Net.WebResponse response;
IWebProxy iwp = System.Net.WebRequest.GetSystemWebProxy();
request = System.Net.WebRequest.Create(
"http://store.bearvalley.com/live/camimage_00001.jpg");
request.Proxy = iwp;
response = request.GetResponse();

When I hover Proxy in the debugger I can see my proxy server address but I'm
still getting the error when it executes the GetResponse call. Any more
suggestions would be appreciated.

Thanks! ;^)
Richard

Nicholas Paldino said:
Richard,

You might want to change the code that calls the static Create method to
call off the WebRequest class. It won't fix your problem, but it makes the
code a little more accurate (considering that you are getting an
HttpWebRequest based on the URL).

The reason it works for you in your browser is because your browser is
set up correctly to use a proxy. You have to do the same thing in code,
creating an instance of the WebProxy class, setting the properties on it,
and then setting the Proxy property to that WebProxy instance.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

My webcam app runs OK on XP but not on Vista. Here's my code snippet that
has been working up until now:

System.Net.WebRequest request;
System.Net.WebResponse response;
request = System.Net.FileWebRequest.Create(
"http://store.bearvalley.com/live/camimage_00001.jpg");
response = request.GetResponse();

When it tries to execute the request.GetResponse() call I get the
following
exception:
The remote server returned an error: (407) Proxy Authentication Required.

I can paste the uri into my browser and it works OK.

Any assistance would be greatly appreciated.

Thanks! ;^)

Richard
 
R

Richard

It's now working! After much groping around I stumbled on this as my solution:

WebRequest request;
WebResponse response;
WebProxy wp = new WebProx();
wp.UseDefaultCredentials = true;
request = System.Net.WebRequest.Create(
"http://store.bearvalley.com/live/camimage_00001.jpg");
request.Proxy = wp;
response = request.GetResponse();

Thanks Nicholas for steering me in the right direction! ;^)
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top