Log in to another site using asp.net

Hey guys, I'm trying to make a site that can subscribe to other sites for users and get certain information. For example: a web forum that automatically pulls out statistics for your game. My site will have to go to the game url, fill in the username and password, log in, and then read the html after logging in (this is the simple part for which I would just use the HTML flexibility package or something like that) Is this procedure possible in asp.net?

+3
source share
6 answers

Yes.

, . - , HTTP, , -, . , , , , ' POST . , MSDN , , ( ):

WebRequest request = WebRequest.Create ("http:/www.site.com/loginPostback");
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "username=blah;password=blah";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();

HTML-, , .

, API. , . , - OAuth, .

+4

. Fiddler2 , , . WebClient, . ! WebClient cookie. , , cookie, .

HTTP-. , Credentials WebClient , .

+3
+1

SSO (Single Sign On).

- , , .Net. , , . , , ( ).

, , SSO.

+1

, -. , HTML HTTP [], .

, , . =)

0

Why not consider some other authentication mechanism through a popular site such as OpenID, Facebook, or some openly accessible authorization store?

Brian

0
source

All Articles