C #: Simulate the initial application of requests to create web game aids (kaixin.com for parking space, biting people, buying a house, virtual friends, gifts)

Source: Internet
Author: User

Kaixinnet auxiliary tool, which can be operated automatically.

Preparation tool: wsockexpert (for packet capture)

Principle: analyzes all operation connections of kaixin.com.ProgramSimulate requests for batch operations!

Take kaixinnet login as an example and simulate login with a program.

Select the listener page and log in from the browser.

 

After clicking the "log in" button, the packet capture program will change. Because we interacted with kaixin.com server just now and needed to send data to the outside, we obtained the following results through packet capture data:

 

Post/login. php HTTP/1.1
Accept: Application/X-Shockwave-flash, image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/vnd. MS-Excel, application/vnd. MS-PowerPoint, application/MSWord ,*/*
Referer: http://www.kaixin001.com/
Accept-language: ZH-CN
Content-Type: Application/X-WWW-form-urlencoded
UA-CPU: x86
Accept-encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1);. Net CLR 2.0.50727; CBA)
HOST: http://www.kaixin001.com/
Content-Length: 48
Connection: keep-alive
Cache-control: No-Cache
COOKIE: _ uid = 2121099; serverid = _ srv134-110 _

Mailto: url = % 2f & amp; email = dirain ** @ yahoo.cn & amp; Password = 19920226

 

/Login. php is the login request address. All connections should be http://www.kaixin001.com/login/login.php.

The lowest mailto: url = % 2f & amp; email = dirain ** @ yahoo.cn & amp; Password = 19920226 should be the passed parameter, we can see that only the account and password are submitted as parameters, and the request type is post.

 

With this information, you can simulate a request through the webrequest of C # To implement the login operation,CodeIt is also very simple.

Request Simulation Method

 

Code

///   <Summary>
/// Send POST requests
///   </Summary>
///   <Param name = "url"> Request address </Param>
///   <Param name = "postdata"> Parameters </Param>
///   <Returns> </returns>
Public Webresponse dopost ( String URL, String Postdata)
{
Try
{
System. gc. Collect ();
Thread. Sleep ( This . Defer );
Byte [] Parambyte = Encoding. utf8.getbytes (postdata ); // Conversion
Httpwebrequest webrequest = (Httpwebrequest) webrequest. Create (URL );

Webrequest. Method =   " Post " ;
Webrequest. contenttype =   " Application/X-WWW-form-urlencoded " ;
Webrequest. Referer =   " Http://www.kaixin001.com/app/app.php? Aid = 1040. " ;
Webrequest. Accept =   " Application/X-Shockwave-flash, image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/vnd. MS-Excel, application/vnd. MS-PowerPoint, application/MSWord, application/X-Silverlight ,*/* " ;
Webrequest. useragent =   " Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;. Net CLR 2.0.50727; CBA) " ;
Webrequest. contentlength = Parambyte. length;
Webrequest. cookiecontainer =   This . Cookies;
// Webrequest. Timeout = 5000;
Stream newstream = Webrequest. getrequeststream ();
Newstream. Write (parambyte, 0 , Parambyte. Length ); // Write Parameters
Newstream. Close ();
Return Webrequest. getresponse ();
}
Catch (Exception CE)
{
Throw CE;
}
}

 

When simulating a request, you must note that the cookie is synchronized; otherwise, the session cannot be maintained.

Webrequest. cookiecontainer = This. Cookies;

This statement is the key code used to maintain the session. This. Cookie is a non-local variable, so that the cookie of the previous operation can be used for each call.

 

///   <Summary>
/// Cookie related to the request (used to maintain the session)
///   </Summary>
Protected Cookiecontainer cookies =   New Cookiecontainer ();

 

As long as the cookiecontainer attribute of the webrequest object is assigned to the declared cookiecontainer object during each request, instead of re-instantiating it.

Log on to kaixin.com

 

Code

///   <Summary>
/// Log on to kaixin.com
///   </Summary>
///   <Param name = "Account"> User Name </Param>
///   <Param name = "password"> Password </Param>
///   <Returns> User personal information </Returns>
Public   Virtual Userinfoentity login ( String Account, String Password)
{
Try
{
// Patchwork Login Parameters
String Param =   " Url =/home/& invisible_mode = 0 & Email = "   + Account +   " & Password = "   + Password;
Webresponse response =   This . Dopost ( " Http://www.kaixin001.com/login/login.php " , Param );
Streamreader =   New Streamreader (response. getresponsestream (), encoding. utf8 );

// If the returned address is the home page, the logon is successful.
If (Response. responseuri. tostring () =   " Http://www.kaixin001.com/home/ " )
{
// Read the returned stream
String Body = Streamreader. readtoend ();

// Login fails if the following information exists:
If (Body. indexof ( " Incorrect account or password! Retry once? " ) ! =   - 1 )
{
Return   Null ;
}
Else
{
// Run
//
}
}
Else
{
Response. Close ();
Streamreader. Close ();
}
}
Catch
{
}
}

This is a simple simulated request login code. In fact, it is an auxiliary tool for web programs. What is important is to analyze data, the most important step in this example is to use the packet capture tool to capture the submission method and Transfer Parameters of kaixin.com. If you do not need a packet capture tool to capture, you can also analyze the HTML form to obtain the transfer method, but this will be very troublesome.

// Does post automatically jump ??

Request. allowautoredirect =True;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.