Setting WebClient Credential

G

Guest

Dear all,

I wrote a function to use WebClient to retrieve information from the Web.
It worked fine. However, the proxy setting of our firm has been changed.
Proxy authentication is required now but I have no idea how to set the
credential for the WebClient. I went through the .Net document and only
found an example of reading credentials. Can anyone give me the idea how to
set the WebClient credential?

Thanks for any help
 
G

Guest

I wrote a function to use WebClient to retrieve information from the Web.
It worked fine. However, the proxy setting of our firm has been changed.
Proxy authentication is required now but I have no idea how to set the
credential for the WebClient. I went through the .Net document and only
found an example of reading credentials. Can anyone give me the idea how to
set the WebClient credential?

The way I do it is as follows:

Dim req As Net.WebRequest = Net.WebRequest.Create(New Uri(Url))
If UserName <> "" And Password <> "" Then
req.Credentials = New Net.NetworkCredential(UserName, Password)
End If

This code is from a vb sub that takes string inputs Url, UserName, and
Password, and it precedes calling req.GetResponse(). The code is
credential-less if UserName or Password is empty, otherwise it sets
req.Credentials in the simplest way possible. It worked for me (first try!)
on the one web site where I needed credentials. I was confused by the
documentation of this topic and I consider myself a lucky novice, so no
guarantees. Good luck.
 

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