/* before writing any html text. This indicates the end of the */
/* header and the start of text that is served from the server. */
/* This text is usually html but can be plain/text. */
/* */
/* Input: Data read from standard input or QUERY_STRING that is */
/* entered in an HTML form. */
/* */
/* Output: The data read from standard input is written as is to */
/* standard output. This information would then be served by */
/* the HTTP server. */
/* */
/* Exit Normal: */
/* */
/* Exit Error: None */
/* */
/**********************************************************************/
void main()
{
char *stdInData; /* Input buffer. */
char *queryString; /* Query String env variable */
char *requestMethod; /* Request method env variable */
char *serverSoftware; /* Server Software env variable*/
char *contentLenString; /* Character content length. */
int contentLength; /* int content length */
int bytesRead; /* number of bytes read. */
int queryStringLen; /* Length of QUERY_STRING */
/*------------------------------------------------------------------*/
/* The "Content-type" is the minimum request header that must be */
/* written to standard output. It describes the type of data that */
/* follows. */
/*------------------------------------------------------------------*/
printf("Content-type: text/html\n");
/*------------------------------------------------------------------*/
/* VERY IMPORTANT! An extra newline must be written */
/* after the request header. In this case the request header is */
/* only the Content-type. This tells the HTTP server that the */
/* request header is ended and the data follows. */
/*------------------------------------------------------------------*/
printf("\n");
/*------------------------------------------------------------------*/
/* This html text consists of a head and body section. The head */
/* section has a title for the document. The body section will */
/* contain standard input, QUERY_STRING, CONTENT_LENGTH, */
/* SERVER_SOFTWARE and REQUEST_METHOD. */
/*------------------------------------------------------------------*/
printf("<html>\n");
printf("<head>\n");
printf("<title>\n");
printf("Sample AS/400 HTTP Server CGI program\n");
printf("</title>\n");
printf("</head>\n");
printf("<body>\n");
printf("<h1>Sample AS/400 ILE/C program.</h1>\n");
printf("<br>This is sample output writing in AS/400 ILE/C\n");
printf("<br>as a sample of CGI programming. This program reads\n");
printf("<br>the input data from Query_String environment\n");
printf("<br>variable when the Request_Method is GET and reads\n");
printf("<br>standard input when the Request_Method is POST.\n");
/*------------------------------------------------------------------*/
/* Get and write the REQUEST_METHOD to stdout. */
/*------------------------------------------------------------------*/
requestMethod = getenv("REQUEST_METHOD");
Chapter6. Sample programs (in Java, C, and RPG) 97