Click here to Skip to main content
13,052,342 members (57,240 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to write a program which connects to a web site which asks for credentials and do something or read the returned data. See here [user : 'admin' pass : 'mypass'].
I'm wondering how can I do that. The programming language doesn't matter.

Thanks in advance!
Posted 8-Feb-11 8:35am
Updated 8-Feb-11 8:53am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this example in C#:
// Create a request for your URL. 		
WebRequest request = WebRequest.Create ("");
// If required by the server, set the credentials.
request.Credentials = NetworkCredential("admin", "mypass");
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// Do something with the response you got

That should do it for you.

Marcus Kramer 8-Feb-11 18:27pm
I thoroughly enjoy seeing the "It needs to do something" questions. Well answered.
Manfred R. Bihy 9-Feb-11 7:23am
Thanks Marcus!
e_yasini 9-Feb-11 13:20pm
I tried it but visual studio says 401 unauthorized
Manfred R. Bihy 9-Feb-11 13:33pm
Please try with setting PreAuthenticate of request to true: request.PreAuthenticate = true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 9 Feb 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100