Many people must have used OICQ, and they must have also used its BP machine text messages and mobile phone text messages. Programming friends must want to realize this function.
It would be cool if your program could be sent to mobile phones and BP machines.
Now I will introduce a possible method.
1. Principle
It is different from the paging function of OICQ where both parties can communicate only when they are online. It can send text messages to real pagers. As long as you have access to the Internet, you can do it yourself and send information anytime and anywhere. Even if you are abroad, you can use it to send information to friends in China, and you don’t have to pay international long distance charges. Isn’t it convenient and hassle-free!
2. Analysis
Nowadays, every paging station on the Internet has online services, and web paging is a commonly used one. It is done by accessing the homepage of the paging station on the Internet, and then paging by the information paging system of the paging station. So we only need to use the HTTP protocol to implement network paging. The following is a brief introduction to the HTTP protocol:
Completing a session in HTTP usually requires: 1) The client program establishes a connection with the server 2) Sends a request 3) The server responds to the client 4) Closes the connection
Commonly used HTTP requests are: 1) GET (requesting a web page) 2) HEAD (reading the header of a web page) 3) PUT (requesting a stored web page) 4) POST (attaching a named resource) 5 )DELETE (Delete the World Wide Web) 6)LINK (Connect two existing resources) 7)UNLINK (Disconnect two existing resources)
Commonly used response status codes in HTTP are: (* represents a number between 0-9) 1. 1** (information) 2. 2** (success) 3.4** (client error) 4.5**( Server error)
In fact, the program we want to implement only uses POST and GET requests and receives normal responses. POST can be used to pass the data input by the user to the CGI program in the form of a data stream. CGI uses the Contact-Length environment variable to obtain the data stream information of the corresponding length.
The POST request format is as follows:
POST http://www2.scuta.edu.cn/stu/chatroom/check.asp HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-Powerpoint, application/vnd.ms-Excel, application/msWord, */*
Referer: http://www2.scuta.edu.cn/stu/
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
PRoxy-Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)
Host: www2.scuta.edu.cn
Content-Length: 87
Pragma: no-cache
Cookie: ASPsessionIDQGGGQHHE=ABGNNOJCIGOFCDLBIOLHKAFK
The header structure of the server's normal response is:
200 OK HTTP/1.0 indicates that the data submission was successful
3. Implementation of program
NMHTTP in Delphi can easily implement the data submission mentioned above, and it also supports Proxy, which is also applicable to Internet access through proxy servers, and it is not the SOCKET5 proxy used to send messages in OICQ.
Create a new form and add a ComboBox component, named callto, to store paging objects. For example, Guosen paging has 95908, 94908, 94909, 98062, 98063, 98019, 98035, 98052, 98038, 99055, 98060, 98061 ,98051,98003, 99062, 99016, 99017, 99018, 99019, 99046, 99076; add the component Edit and name it tonumber, which represents the paging number; add the component RadioGroup and name it RadioGroup1, set Caption to the pager type, and add two items to items, each in Chinese machine, Digital machine; Add component Edit, named firstName, used to indicate the last name of the person who sent the page; Add component RadioGroup, named RadioGroup2, Caption is set to the gender of the pager, add two items to items, namely Mr. and Miss; Add The component Memo, named callmsg, is used to input the sent information ( Note: For digital machines, it can only be digital information); add the component NMHTTP, named NMHTTP1; add Checkbox, named ifuseproxy, to determine whether to use a proxy server; add two Edit components, respectively for the software proxy server address, proxy Server port; finally add a command button and set Caption to "Send".
Now take Guosen paging as an example. It can be implemented using GET request. The program code of the "Send" button is as follows:
procedure TForm1.Button1Click(Sender: TObject);
var callstr:string;
begin callstr:='http://tips.gxspace.com/cgi-bin/tips/webpaging?stn_id='+callto.Text+'&page_no='+tonumber.Text;
case RadioGroup1.ItemIndex of
0:callstr:=callstr+'&pager_type=C';
1:callstr:=callstr+'&pager_type=N';
end;
callstr:=callstr+'&firstname='+firstname.text;
case RadioGroup2.ItemIndex of
0:callstr:=callstr+'&title=0';
1:callstr:=callstr+'&title=1';
end;
callstr:=callstr+'&msg='+callmsg.Text+'&answer=null&B1=Send paging';
NMHTTP1.InputFileMode := FALSE;
NMHTTP1.OutputFileMode := FALSE;
NMHTTP1.ReportLevel := Status_Basic;
If ifuseproxy.Checked then
Begin
NMHTTP1.Proxy := Edit1.Text;
NMHTTP1.ProxyPort := StrToInt(Edit2.Text);
End;
NMHTTP1.Get(callstr);
end;
Some paging (such as Runxun paging cannot be implemented with the above GET request, it requires a POST request), the usage is not much different from the above, for example, the following is the POST usage of NMHTTP:
NMHTTP1.InputFileMode:=False;
NMHTTP1.OutputFileMode:=True;
NMHTTP1.ReportLevel:=Status_Basic;
If ifuseproxy.Checked then
Begin
NMHTTP1.Proxy := Edit1.Text;
NMHTTP1.ProxyPort := StrToInt(Edit2.Text);
End;
With NMHTTP1.HeaderInfo do
Begin
Cookie := Edit5.Text;
LocalMailAddress := Edit6.Text;
LocalProgram := Edit7.Text;
Referer := Edit8.Text;
UserID := Edit9.Text;
Password := Edit10.Text;
End;
//Put the data to be submitted in the test.txt file first: the format is stnid=A&pageno=123456...
NMHTTP1.Post('http://www.wocall.com/script/zbwebcall.asp','test.txt');
//The specific usage of NMHTTP is installed in Delphi. There is currently an example of NMHTTP usage under BorlandDelphi5DemosFastNetHttp.
The above are all implemented using NMHTTP. In fact, the WebBrowser component in Delphi can also be used to submit data. The use is like this: Webbrowser1.OleObject.Document.FrontPage_Form1.submit();
Note: WebBrowser1 is the name of the WebBrowser component, Frontpage_Form1 is the name of the form in the web page opened with WebBrowser
The form on the web page looks like this:
<FORM name=FrontPage_Form1 action=http://message.com.cn/cgi-bin/ips/webpaging method=post>
...
</Form>
The implementation method is to use a program to generate a web page based on user input information, then pass WebBrowser1.Navigate (generated web page), and finally submit it to the server Webbrowser1.OleObject.Document.FrontPage_Form1.submit(); This is completed once paging