Software login software DIY
HTTP is one of the main protocols for Web Services. This protocol is used to browse Web pages and submit dynamic website data. The process is to send data requests (read and storage) to the Web server through HTTP sessions ).
Post and get data requests are commonly used in programming. Post can be used to transmit user input data to CGI (Asp, JSP) programs in the form of data streams. cgi then uses the contect-length environment variable to obtain the data stream information of the corresponding length. If the data is successfully submitted, the server returns a normal response with the following header information:
HTTP/1.1 200 OK
Website login is implemented by entering login information by the user, and the CGI program submits the information to the web server. Take the free website submission of Sohu website as an example: first, enter the website logon page on the Sohu homepage, select the logon category of the website, and enter the website information: this process consists of two steps, step 1 fill in the website name and address (http ://...), Step 2 fill in some detailed information, and then you can submit it. The second step is to truly save data. The core webpage code (simplified) is:
<Form name = "form1" method = "Post"
Action = "/regurl/regform. asp? Step = create & Class = c016015005002
& Sitename = website name & url = http: // website address"
Onsubmit = "Return checkform ()">
<Input type = "hidden" name = "Step" value = "CREATE">
Website description:
<Textarea name = "Description" rows = "2" Cols = "60"> </textarea>
......
</Form>
(Note: c016015005002 varies depending on the selected website category)
Our program uses the tnmhttp component perfectly encapsulated by Delphi to simulate button submit submission on the webpage, so as to quickly and accurately register the website with program code.
In this example, the author program can successfully complete the website "100,000 why" (http://helps100000.yeah.net) login, log on to the "Home> company> computer and Internet> Computer Software> Database" category. The interface components of the program are: one webbrowser component and three memo components, which are used to display the feedback page and some prompt information after logon. One nmhttp1 component is the core component of the Program. There is also a button.
In fact, the core code of the program is as follows:
Nmhttp1.post ('HTTP: // db.sohu.com/regurl/regform.asp?
Step = create & Class = c016015005002 & sitename = 100,000. Why?
& Url = http://helps1000000.yeah.net ', 'postdata.txt ');
The post method has two parameters, 1st representing the action part of the form, and 2nd representing a string consisting of the values of each parameter in the <input> tag. Because the outputfilemode attribute of nmhttp1 is set to true, the strings of the 2nd parameters are placed in an external text file postdata.txt, and the content of postdata.txt is (no branch ):
Description = computer technology collection and application skills & KEYWORDS = computer skills
& District = mountains & City = Xi'an & contact = Zhang Qing & Email = zhangking@263.net & memo = No
This string is obtained by analyzing the webpage code.
After the program runs, click the "website registration" button. if the machine is already connected to the Internet, it will be like registering a website on a webpage, soon, the "Registration successful" or "error: This website has been registered" page will be returned in webbrowser1.
This program is successfully adjusted in Windows 98, ie5.0, and Delphi5.0 environments. On this basis, we can use multithreading and other technologies to create a utility software similar to "Login cavalry.
// Complete source code of the program is as follows:
Unit unit1;
Interface
Uses
Windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
Stdctrls, olectrls, shdocvw, psock, nmhttp, extctrls;
Type
Tform1 = Class (tform)
Nmhttp1: tnmhttp;
Panel1: tpanel;
Button1: tbutton;
Memo3: tmemo;
Memo2: tmemo;
Memo1: tmemo;
Panel2: tpanel;
Webbrowser1: twebbrowser;
Procedure button1click (Sender: tobject );
Procedure nmhttp1success (CMD: Transaction type );
Procedure nmhttp1failure (CMD: Transaction type );
Procedure formcreate (Sender: tobject );
Private {private Declarations}
Public {public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.formcreate (Sender: tobject );
Begin
Webbrowser1.navigate ('about: blank ');
End;
Procedure tform1.button1click (Sender: tobject );
Begin
With nmhttp1 do
Begin
Inputfilemode: = false;
Outputfilemode: = true;
Reportlevel: = status_basic;
End;
With nmhttp1.headerinfo do
Begin
COOKIE: = '';
Localmailaddress: = '';
Localprogram: = '';
Referer: = '';
Userid: = '';
Password: = '';
Try
Nmhttp1.post ('HTTP: // db.sohu.com/regurl/regform.asp?
Step = create & Class = c016015005002 & sitename = 100,000. Why?
& Url = http://helps1000000.yeah.net ', 'postdata.txt ');
Except
Showmessage ('error! ');
End;
End;
End;
Procedure tform1.nmhttp1success (CMD: Role type );
Begin
Case cmd
Restore post:
Begin
Memo1.text: = nmhttp1.header;
Memo2.text: = nmhttp1.body;
Webbrowser1.oleobject.doc ument. Body. innerhtml: = nmhttp1.body;
Memo3.lines. Add ('HTTP post successful ');
End;
End;
End;
Procedure tform1.nmhttp1failure (CMD: Role type );
Begin
Memo1.text: = nmhttp1.header;
Memo2.text: = nmhttp1.body;
Case cmd
Restore post:
Memo3.lines. Add ('HTTP post failed ');
End;
End;
End.
------------------------------------------------
Zhang Qing (Xi'an net-E Software System Engineering Company)
Email: zhangking@263.net
Http://soft.why100000.com