Decoding CGI Content From Alternate Sources
[Previous] [Main] [Next]

 
If your platform or web server doesn't support environment variables or input redirection (e.g., cin), the standard htmlCgi behavior may not recognize content submitted to your application by the server.  
 
The example below demonstrates the use of the Initialize() method to feed content data to the htmlCgi class for decoding from another source, such as a data structure or other server API function.  
 
Example
 
#include <stdio.h>  
#include <stdlib.h>  
#ifdef _WINDOWS  
#include <strstrea.h>  
#else  
#include <strstream.h>  
#endif  
#include <dcmicro/htmlpp/htmlpp.h>  
 
 
// Test using POST method.  
void SubstitutePost( htmlPage& page )  
{  
   //  Create a stream object that htmlCgi can accept  
   strstream url_data ;  
   url_data << "name1=value1&name2=value2&name3=value3" ;  
 
   //  Create the cgi object, setting the necessary member variables  
   //  as if the input were coming from cin (standard input).  
   htmlCgi  server ;  
   server.Request_Method = "POST" ;  
   server.Content_Type   = "application/x-www-form-urlencoded" ;  
   server.Initialize( url_data ) ;  
 
   //  Output all CGI data to show that html++ has properly decoded the values  
   String name = server.EnumerateName( "" ) ;  
   while ( name != "" )  
   {  
      page << htmlBold( name )   
           << " : "  
           << server( name ) // the value  
           << htmlBreak() ;  
 
      //  loop for next form field  
      name = server.EnumerateName( name ) ;  
   }  
}  
 
 
// Test using GET method.  
void SubstituteGet( htmlPage& page )  
{  
   //  Create the cgi object, setting the necessary member variables  
   //  as if the input were coming from the QUERY_STRING environment variable.  
   htmlCgi  server ;  
   server.Request_Method = "GET" ;  
   server.Query_String = "name4=value4&name5=value5&name6=value6" ;  
   server.Initialize() ;  
 
   //  Output all CGI data to show that html++ has properly decoded the values  
   String name = server.EnumerateName( "" ) ;  
   while ( name != "" )  
   {  
      page << htmlBold( name )   
           << " : "  
           << server( name )  // the value  
           << htmlBreak() ;  
 
      //  loop for next form field  
      name = server.EnumerateName( name ) ;  
   }  
}  
 
 
int main( void )  
{  
   htmlCgi    server ;  
   htmlPage   page( "html++ form input example" ) ;  
 
   //  Test the POST method  
   SubstitutePost( page ) ;  
   //  Add some space to separate the output  
   page << htmlBreak() << htmlBreak() ;  
   // Test the GET method  
   SubstituteGet( page ) ;  
 
   server << page ;  
   return 0 ;  
}  
 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.