Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

Im trying to set the username and password for a URI using the URIBuilder class.

 

Im using the following code (except with real values for site, user, pword) :

 

       Dim i As New UriBuilder()
       i.Scheme = "http"
       i.Host = "www.site.com"
       i.UserName = "user"
       i.Password = "pword"

       Dim myRequest As WebRequest = WebRequest.Create(i.Uri)

      Dim myResponse As WebResponse = myRequest.GetResponse()

 

However, an unathorized error occurs at the myResponse line.

 

When i debug, it appears that the username and password is not set.

 

can anyone help?

 

thanks,

danny.

  • 3 months later...
  • *Gurus*
Posted
Dim oWebRequest As WebRequest = WebRequest.Create("http://www.google.com/")
Dim oNetworkCredential As NetworkCredential = New NetworkCredential("user", "password")

oWebRequest.PreAuthenticate = True
oWebRequest.Credentials = oNetworkCredential

Dim oWebResponse As WebResponse = oWebRequest.GetResponse()

Posted

Hi all,

 

Derek, that looks like a nice workaround.

 

BTW.. i had posted the original problem way back on a microsoft board and they got back saying that it was a bug and that they'd put in a request to fix it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...