Question HTTP authorization header

erics44

Member
Joined
Dec 9, 2009
Messages
12
Programming Experience
Beginner
Hi
Does anyone know how to pass credentials in the HTTP authorization header using basic authentication semantics?


Thanks in advance
 
If you mean for a Http request have a look at these:
HttpWebRequest.Credentials Property (System.Net)
WebClient.Credentials Property (System.Net)

If you mean setting the transport level authentication for a web service request there are similar Credentials/ClientCredentials properties for this with the service proxy (inherits SoapHttpClientProtocol or ClientBase(Of TChannel)).

having read through the http requests it doesnt actually tell me anywhere how to set the username and password

could you help?

thanks a lot
 
thanks again for taking the time

I think the issue im having is that there is no example code to say

credentials.service = "http://webservice"
credentials.username= "username"
credentials.password = "password"
 
I don't know what you mean by that. All you should need to do is this for service references:
VB.NET:
proxy.ClientCredentials.UserName.UserName = "user"
proxy.ClientCredentials.UserName.Password = "pass"
or this for web references:
VB.NET:
Dim proxy As New localhost.Service
proxy.Credentials = New Net.NetworkCredential("user", "pass")
When such a NetworkCredential object is assigned these credentials are passed to any url and authentication type that requires it. CredentialCache object can be used if you want to, but it is not necessary, it's primary purpose is to be able to add different credentials for different urls/auths to the same request object, it can also be used to hide credentials from any service that is not the target of those credentials. You can easily verify this by using the GetCredential method that is available from either of those classes, return value is:
The NetworkCredential that is associated with the specified URI and authentication type, or, if no credentials are available, a null reference (Nothing in Visual Basic).
 
thanks again for the reply

if i go off your web refence code

is the localhost.service is the name of the web service?

so if my webservice was called webServiceService I would have

Dim proxy as new webServiceService
proxy.Credentials = New Net.NetworkCredential("user", "pass")

?

and i can just put this in a page load event say and the credentials will be set?
 
If you set the credentials for the object they stay, yes, for the lifetime of the object, there is no hidden unexpected events that could occur that would cause the object to suddenly loose its credentials.
 
Back
Top