A GET request is the way we send a request when we enter a URL in the browser's address bar, or when we define a form (form) in HTML, the Action property is set to the way it works;
The GET request string follows the URL with a question mark "?". The start string, but does not include a question mark. such as a request: http://127.0.0.1/cgi-bin/out.cgi?ThisIsTheGetString
In the above URL, "Thisisthegetstring" is the GET request string.
Before entering our own CGI code, the Cgic library has taken this string in advance, and we can get it directly in the program, simply by adding the following statement before the Cgimain method you write: extern char * cgiquerystring;
Now give a simple example, this example is very similar to the previous test program, except that the output of the program is the user input of the GET request string. Download: test.c #include <stdio.h> #include "cgic.h" #include <string.h> #include <stdlib.h> extern char *c giquerystring; int Cgimain () {Cgiheadercontenttype ("text/html"); fprintf (Cgiout, "
Suppose that the program is compiled into OUT.CGI (compiled by the previous article) and deployed to the Cgi-bin directory of the Web server, when the user enters the URL string given at the beginning of this article in the browser's address bar, the browser page displays: thisisthegetstring
We can also write an HTML page for the test: Download: test.html
The file's deployment structure should be:
|test.html
|--cgi-bin/out.cgi
You can try, through the browser to access the http://127.0.0.1/test.html, enter some characters in the text box, and click the Submit button, and then you can see the results of the CGI program: the text box entered the character is displayed in the browser.