0

I want to login using the WebRequest class.

var http = WebRequest.Create("http://www.xxx.nl/admin/xxx.php?id=3005");

I think I need to do something with the NetworkCredential Class but do I only need to fill in the username and password?

Also, I don't know how I would eventually receive the page data.

Sam
  • 7,252
  • 16
  • 46
  • 65
matthy
  • 8,144
  • 10
  • 38
  • 47

1 Answers1

2

You need to provide an implementation of the ICredentials class to WebRequest. NetworkCredentials is an implementation of ICredentials that you can use.

The specific details will depend on your .htaccess file. I'll assume that your'e using basic authentication with usernames and passwords defined in the .htaccess file. You'll need to create a new NetworkCredentials object and pass in the username and password defined in the .htaccess file. I'm not 100% sure, but you might need to set the NetworkCredentials.Domain property to match the "realm" defined in the .htaccess file.

Have a look at this MSDN page for an example of how to create a NetworkCredentials instance and use it with a WebRequest instance.

dariom
  • 4,413
  • 28
  • 42