Web_http get-post command message viewer
ADRIAN BACAIANU
This article describes a tool for reviewing the original information using the HTTP GET and Post commands from the web server.
Introduction
THIS Utility Is Just A Wrapper Around Reusable Functions That Allow Programmatic Access To The Web Through A Sort of 'Mini-Browser' Embedded Inside Your Program.
White, translation ...]
These codes are useful. For example, some programs called Spiders, BOTS or CRAWLERS, focus on a series of web pages, like how users surf from a web page to another web page. These programs are often used to classify the web page, importing external data from the web page or simply sending a command to a web server. You can extend our feature of the class provided to achieve information from the Internet in a variety of ways.
There are a lot of third-party DLL dynamic libraries and schemes that get data from the website. The methods provided herein are completely independent, and it does not rely on Wininet, Internet Explorer, Netscape, or similar software installed as prerequisites, except for Winsock. Winsock is the body of the Windows TCP / IP protocol stack and applies to any computer that can run the browser.
Each Internet protocol is organized as an RFC (Request for Comments) documentation. The HTTP protocol is in RFC1945. In addition, RFC1630, RFC 1708, and RFC1808 describe the format of the URL.
At http://www.rfc-editor.org/, you can find a complete set of RFC documents.
achieve
The core of this program is the Request class. Its key approach is Sendhttp (), and this method receives 5 parameters to return an integer. The first parameter is the URL of POST or GET. The second parameter specifies the HTTP header information to be passed in this request. The third and fourth parameters specify the data and upload data length. The fifth parameter is a message to the HTTPRequest structure to save the HTTP header information, sent and returned from the web server. The Sendhttp () method returns 0 when POST or GET is successful, otherwise 1 represents an error.
The Sendhttp () method first processes the URL string. A URL is a clear resource location address on the specified Internet. A URL has several components, some are optional. An example of a URL is as follows: http://www.codetools.com/index.html
The first part of the URL is an agreement that describes how to receive resources. The protocol is the host name. It can be a domain name or an IP address. The host name is behind a port number. Each protocol has a default port number without explicitly specifying ports. The default port number of the HTTP protocol is 80. The port number is followed by a specified web server current request (?). If not specified, the default is '/', it requests the root directory of the web server.
Next, Sendhttp () initializes the Winsock library by calling Winsock's WSAStartup () method. Then create a socket connection, sendHTTP () sends a request to the server. There are two forms of HTTP requests. The first, simple form is HTTP GET.
An HTTP GET does not send any additional information to the server, except for the header and the URL. An HTTP get naming usually uses the URL itself to send attachment information: http://localhost/projects/http/testget.asp? Name = fred & agn = 22
The second form, the http post command, which is accompanied by sending requests, but separating with the URL. Typically, an http post command contains the following head: Content-Type: Application / X-WWW-FORM-URLENCODED
Without the head, some web servers (typical, asked on IIS) will not be reorganized. A http post command has two parts. The first part is the HTTP head, just as in GET. The head contains the actual request and the additional information piece. Unlike Get, a post command contains data after the header (separated by a blank line). After the web server receives the GET or POST request, it will send a response. The response contains two parts: head information and back data (separated by a blank line).
The first line is the HTTP header, which specifies the status of the request. It starts with a data error code.
100-199 is an information message or unused. 200-299 request success. 300-399 Indicates the resource requested to be deleted; the web server is used to redirect. 400-499 indicate client error .500-599 Indicates server errors.
The head is behind the data of GET or POST. They are usually displayed on the browser screen.
Dialog box
Use the MFC dialog project to do a request for a request class. Add an instance of a Microsoft Web Browser control on a dialog container. He can manipulate data, make and get, post similar commands very easy. This control is used for two ways:
1. When the user uses the browser to generate a request, the control triggers the OnBeforenaviGate2 event captured by the dialog program. In this case, the onBeforenaviGate2Explorer1 method is used to capture the header information and POST data sent by the GET or POST command. 2. If the user wants to use the SendHTTP engine, enter the required URL, complete the 'SendHTTPrequest' and 'PostData' (if is a POST) fields, chack the radio button GET or POST and click on the 'Go' button. The IE Control Will Load The Html Formatted Data Received from Sendhttp () Function In The M_HttpBody String Variable. The Html Loading is Done in OnButtonViewHTTP ().
Htmldocument2 * phtmldocument2;
LPDISPATCH LPDISPATCH;
LPDISPATCH = M_Browser.getDocument ();
IF (LPDISPATCH)
{
HRESULT HR;
HR = lpdispatch-> queryinterface (IID_IHTMLDocument2,
(Lpvoid *) & phtmldocument2;
LPDISPATCH-> Release ();
IHTMLELEMENT * PBODY;
HR = phtmldocument2-> get_body (& pbody);
BSTR BSTR;
BSTR = m_httpbody.allocsysString ();
PBODY-> PUT_INNERHTML (BSTR); // Insert The HTML
Sysfreeestring (BSTR);
PBODY-> Release ();
}
usage
Input the URL address and click on the Go button. On the right there is a mini-browser with your page. Navigating on links and buttons on this page and in the 'PostData', 'SendHTTPrequest' and 'ReceiveHTTPrequest' will receive the corresponding Data. The Radio Buttons Get / Post Are Modified Automatic - The IE Instance Knows if you make an get (you putton). Enter the URL address, click the Go button. There will be a micro browser that displays you requesting a web page. You are able to input your header in the 'SendHTTPrequest' edit box and your POST data in the 'PostData' edit box, and then push the 'Go' button. The browser will navigate to your address using the headers and data submitted from ' SendhttpRequest 'and' PostData 'Fields.
Use the test.asp and testpost.asp files from Web Directory to test your get / post utility:
Use the TestGet.asp and TestPost.asp files in the web directory:
About author
I have been programmed for more than 4 years and have extensive experience in C , ASP, PASCAL, MFC, COM , ATL, TCP / IP, HTTP protocol, XML, XSL, SOAP, and SQL. In the past two years, I am widely engaged in the work of the Finance Website Backstage (Database, N-layer architecture). To sign and (or) procurement can be contacted with me via adrian_bacaianu@yahoo.com.