Cgic Concise Tutorial 2: Getting GET request string

Source: Internet
Author: User

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.

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.