adsense


Saturday, 28 November 2015

C++ LANGUAGE SIMPLE URL EXAMPLE: GET METHOD

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



C++ LANGUAGE SIMPLE URL EXAMPLE: GET METHOD





Simple URL Example: Get Method 


Here is a simple URL which will pass two values to hello_
get.py program using GET method. 

/cgi-bin/cpp_get.cgi?first_name=ZARA&last_name=ALI 

Below is a program to generate cpp_get.cgi CGI program to handle 
input given by web browser. We are going to use C++ CGI library 
which makes it very easy to access passed information: 

#include <iostream> 
#include <vector>   
#include <string>   
#include <stdio.h>   
#include <stdlib.h>  
 
#include <cgicc/CgiDefs.h>  
#include <cgicc/Cgicc.h>  
#include <cgicc/HTTPHTMLHeader.h>  
#include <cgicc/HTMLClasses.h>   
 
using namespace std; 
using namespace cgicc; 
 
int main () 
{ 
   Cgicc formData; 
    
   cout << "Content-type:text/html\r\n\r\n"; 
   cout << "<html>\n"; 
   cout << "<head>\n"; 
   cout << "<title>Using GET and POST Methods</title>\n"; 
   cout << "</head>\n"; 
   cout << "<body>\n"; 
 
   form_iterator fi = formData.getElement("first_name");   
   if( !fi->isEmpty() && fi != (*formData).end()) {   
      cout << "First name: " << **fi << endl;   
   }else{ 
      cout << "No text entered for first name" << endl;   
   } 
   cout << "<br/>\n"; 
   fi = formData.getElement("last_name");   
   if( !fi->isEmpty() &&fi != (*formData).end()) {   
      cout << "Last name: " << **fi << endl;   
   }else{ 
      cout << "No text entered for last name" << endl;   
   } 
   cout << "<br/>\n"; 
 
   cout << "</body>\n"; 
   cout << "</html>\n"; 
    
   return 0; 
} 
Now, compile the above program as follows: 

$g++ -o cpp_get.cgi cpp_get.cpp -lcgicc 
Generate cpp_get.cgi and put it in your CGI directory 
and try to access using following link: 

/cgi-bin/cpp_get.cgi?first_name=ZARA&last_name=ALI 
This would generate following result: 
First name: ZARA  
Last name: ALI 


No comments: