Web (vi)---fastcgi advanced (Request and response)

Source: Internet
Author: User

Next to the section, the last section only responds---cout, this section gets the query_string of the address bar, and then responds.

I. Req_resp.cpp.

#include <stdlib.h>#include<string.h>#include<unistd.h>#include"fcgio.h"#include"fcgi_config.h"using namespacestd;intMain (void){    intCount =0; LongPID =Getpid (); Streambuf* Cin_streambuf =Cin.rdbuf (); Streambuf* Cout_streambuf =Cout.rdbuf (); Streambuf* Cerr_streambuf =Cerr.rdbuf ();    Fcgx_request Request;    Fcgx_init (); Fcgx_initrequest (&request,0,0);  while(Fcgx_accept_r (&request) = =0{fcgi_streambuf cin_fcgi_streambuf (request).inch); Fcgi_streambuf cout_fcgi_streambuf (Request. out);        Fcgi_streambuf cerr_fcgi_streambuf (Request.err); Cin.rdbuf (&cin_fcgi_streambuf); Cout.rdbuf (&cout_fcgi_streambuf); Cerr.rdbuf (&cerr_fcgi_streambuf); cout<<"content-type:text/html\r\n"                "\ r \ n"                ""<< PID <<""                ""<< ++count <<""; cout<<"";  for(inti =0; Request.envp[i]; ++i) {Char* Findquerystr =NULL; Findquerystr= Strstr (Request.envp[i],"query_string"); if(findquerystr) {cout<< Request.envp[i] <<'\ n';    }}} cin.rdbuf (CIN_STREAMBUF);    Cout.rdbuf (COUT_STREAMBUF);    Cerr.rdbuf (CERR_STREAMBUF); return 0;}

Two. Compile and run.

#g + o req_resp req_resp.cpp-i/usr/local/include-l/usr/local/lib-lfcgi-lstdc++-lfcgi++

#./Req_resp

If there is a compile or runtime error (typically a library problem), refer to the previous section of the workaround.

Three. Copy the CGI to Ngix (the target path is not created manually)

CP ***/req_resp/usr/local/nginx/cgibin

Four. Start spawn-fcgi.

/usr/local/nginx/sbin/spawn-fcgi-a 127.0.0.1-p 8088-f/usr/local/nginx/cgibin/req_resp

Five. Access.

Note: Python index.py is already running in the case.

Browser Address bar: localhost/req_resp.cgi?his_is_from_brower_input&hello=1&world=2

Note that the query_string displayed is the content after the Address bar question mark.

The browser appears as:

pid:4072

Request Number:2

Request Environment

query_string=this_is_from_brower_input&hello=1&world=2

Web (vi)---fastcgi advanced (Request and response)

Related Article

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.