Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HTTP Authentication with a C# WebRequest

I want to make a web request to a page that needs authenticating. How would I go about doing this? I found something that said possibly to use the Credentials property, but I'm not sure how to use it.

like image 441
The.Anti.9 Avatar asked Apr 02 '09 00:04

The.Anti.9


People also ask

How do I use Basic HTTP authentication?

HTTP basic authentication is a simple challenge and response mechanism with which a server can request authentication information (a user ID and password) from a client. The client passes the authentication information to the server in an Authorization header. The authentication information is in base-64 encoding.

How do I send my credentials to http request?

It is indeed not possible to pass the username and password via query parameters in standard HTTP auth. Instead, you use a special URL format, like this: http://username:[email protected]/ -- this sends the credentials in the standard HTTP "Authorization" header.

What is HTTP authentication method?

HTTP Basic authentication is a simple authentication method for the client to provide a username and a password when making a request. This is the simplest possible way to enforce access control as it doesn't require cookies, sessions or anything else.


1 Answers

Assign a new NetworkCredential instance to the Credentials property:

webClient.Credentials = new NetworkCredential("Mehrdad", "Password"); 
like image 96
mmx Avatar answered Oct 02 '22 23:10

mmx