Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Perl PHP Python
Hi!
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 9:35am
Edited 8-Feb-11 9:53am
v2

1 solution

Rate this: bad
good
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 ("http://esihaj.com/phpar");
// 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.
 
Cheers!
  Permalink  
v2
Comments
Marcus Kramer at 8-Feb-11 18:27pm
   
I thoroughly enjoy seeing the "It needs to do something" questions. Well answered.
Manfred R. Bihy at 9-Feb-11 7:23am
   
Thanks Marcus!
e_yasini at 9-Feb-11 13:20pm
   
hi
I tried it but visual studio says 401 unauthorized
Manfred R. Bihy at 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
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 9 Feb 2011
Copyright © CodeProject, 1999-2014
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