Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set up the proxy for a web request?

Status
Not open for further replies.

Henk1

Programmer
Oct 26, 2001
46
0
0
ZA
Good day,

I am using the following code to get the HTML from a web page. But I get a proxy authentication error.

How would I set up the proxy details (server, port, username and password) for our proxy server to get past it?

Code:
// Setup our Web request
System.Net.WebRequest request = System.Net.WebRequest.Create(pageUrl);
				
request.Timeout = timeoutSeconds * 1000;
								
// Retrieve data from request
response = request.GetResponse();

System.IO.Stream streamReceive = response.GetResponseStream();
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StreamReader streamRead = new System.IO.StreamReader( streamReceive, encoding);
				
// return the retrieved HTML
return streamRead.ReadToEnd();

Any help would be appreciated

Thanks
 
You can try this:

WebRequest myWebRequest= WebRequest.Create("//set the proxy to a correct value.
WebProxy proxy=new WebProxy("myproxy:80");
proxy.Credentials=new NetworkCredential ("username","psw");
myWebRequest.Proxy=proxy;


Hope this help,
Mary
 
Thanks alot for the answer.

I now get another error message saying that the connection was closed. But I think our firewall is blocking my request. I'll try tonight at home.

Thanks again.
 
I'm getting the connection closed error also. Did you figure out the problem?

thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top