URIBuilder

sdlangers

Centurion
Joined
Dec 3, 2002
Messages
118
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) :

Visual Basic:
        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.
 
Visual Basic:
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()
 
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.
 
Back
Top