Six Steps to write an ILE C CGI program
来源:互联网 发布:淘宝网怎么推广 编辑:程序博客网 时间:2024/05/21 11:35
Common Gateway Interface (CGI) is a standard, supported by almost all web servers, that defines how information is exchanged between a web server and an external program (CGI program).
CGI programs process data that is received from browser clients. For example, the client fills out a form and sends the information back to the server. Then the server runs the CGI program.
1. The HTTP request is received at the Web server.
2. The HTTP request's Uniform Resource Identifier (URI) is parsed to identify how the request should be processed.
3. Based on the URI contained in the HTTP request, action is taken to server a file or process the request through a CGI program.
CGI applications written and compiled for the IBM i can even run a CGI application that is written and compiled for AIX. The binary output of the compiler is executed directly from IBM i Portable Application Solutions Environment (IBM i PASE).
· V5R4: 5722SS1 33 Portable App Solutions Environment
· V6R1: 5761SS1 33 Portable App Solutions Environment
· V6R1: 5770SS1 33 Portable App Solutions Environment
The server supports CGI programs that are written in C++, Java™, ILE C, ILE RPG, and ILE COBOL.
Before beginning writing a CGI program, you need to know the concept Environment Variables. Environment variable is a kind of data format that the server pass to the CGI program when receiving URL-encoded information.
Now, I will give a CGI programming example written in ILE C.
This example contains instructions to install and execute an ILE RPG C program that prints current date and all of environment variables.
To install the example program, do the following:
- Write a sample ILE C source code, save as samplec.txt.
int main(int args, char* argv[])
printf("Content-type: text/html; /n");
printf("/n");
printf("<br>/n");
printf(" <!--#echo var=/"DATE_LOCAL/" -->");
printf("<br><br><br>/n");
printf(" <!--#printenv -->/n");
printf("<br>/n");
return;
}
- Use the following CL commands to create a directory structure:
- mkdir dir('/qsys.lib/cdemo.lib')
- mkdir dir('/cgidemo')
- mkdir dir('/cgidemo/c')
Note:You may want to ensure *RX authorities for server user profile QTMHHTTP and CGI user profile QTMHHTP1 to these new directories.
- FTP to your server, use the following FTP commands to copy the files to your server:
-
- put samplec.txt /cgidemo/c/samplec.c
- Use the following CL commands to create the program (PGM) object called SAMPLEC:
-
- CRTCMOD MODULE(cgidemo/samplec) SRCSTMF(‘/cgidemo/c/samplec.c’) OUTPUT(*print)
- CRTPGM PGM(CGIDEMO/SAMPLEC) MODULE(CGIDEMO/SAMPLEC) BNDSRVPGM(QHTTPSVR/QZHBCGI)
- Use IBM Web Administration for i (http://<yourservername>:2001/HTTPAdmin) to create an Apache server named, for example, CGIDEMO.
-
- Add a directory for the QSYS library allowing access to the directory and allowing CGI script execution, using the URL Mapping form under Server Propertie.
- Add the directory for the QSYS (CGIDEMO.LIB) library, using the Container Management form under Server Propertie. .
- Under Tools, select Display Configuration File to ensure you have the following CGI related directives:
Listen *:80
ScriptAlias /cgi-bin/ /QSYS.LIB/CGIDEMO.LIB/
<Directory /QSYS.LIB/CGIDEMO.LIB/>
AllowOverride None
order allow,deny
allow from all
SetHandler cgi-script
Options +ExecCGI
Options +Includes
SetOutputFilter INCLUDES
</Directory>
- Restart the CGIDEMO server and access: http://<yourservername>:<port>/cgi-bin/samplec.pgm.
Here is output you should see if the sample ILE C CGI program is successful.
Tuesday, 24-Nov-2009 12:47:24 Central Standard Time
HTTPS=OFF UNIQUE_ID=X33GEAkFr4YAAGbFZPEAAAAH QIBM_USE_DESCRIPTOR_STDIO=Y HTTP_HOST=lp05ut3.rchland.ibm.com:20000 HTTP_USER_AGENT=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.04 (CK-IBM) (CK-IBM) Shiretoko/3.5.5 HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5 HTTP_ACCEPT_ENCODING=gzip,deflate HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_KEEP_ALIVE=300 HTTP_CONNECTION=keep-alive HTTP_COOKIE=CoreID6=89947119652712539186271&ci=90175093,90175080,90225345,90175119,90130510,90175106,90175067; IBMPOLLCOOKIE=""; sauidp=U636780271253923646326; w3ibmProfile=200011161518280656634250576|gAME|897|ECR|en; EPSPROFILE=13E0EC4D2AFB7B2AEABB45941E98CFE8; bprememberme=rwatkin@us.ibm.com; ithc=f61f212d9627ced87c8574f7a2fe7d268d80 HTTP_CACHE_CONTROL=max-age=0 PATH=/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin SERVER_SIGNATURE= SERVER_SOFTWARE=Apache SERVER_NAME=lp05ut3.rchland.ibm.com SERVER_ADDR=9.5.175.134 SERVER_PORT=20000 REMOTE_ADDR=9.49.184.2 DOCUMENT_ROOT=/www/rwatkins/htdocs SERVER_ADMIN=[no address given] SCRIPT_FILENAME=/QSYS.LIB/RWATKINS.LIB/printenv.pgm DOCUMENT_NAME=printenv.pgm REMOTE_PORT=58960 GATEWAY_INTERFACE=CGI/1.1 SERVER_PROTOCOL=HTTP/1.1 REQUEST_METHOD=GET QUERY_STRING= REQUEST_URI=/cgi/printenv.pgm SCRIPT_NAME=/cgi/printenv.pgm DOCUMENT_URI=/cgi/printenv.pgm RULE_FILE=conf/httpd.conf CGI_MODE=EBCDIC CGI_OUTPUT_MODE=EBCDIC IBM_CCSID_VALUE=37 CGI_EBCDIC_CCSID=37 CGI_ASCII_CCSID=819 FSCP=37 NETCP=819 DATE_LOCAL=Tuesday, 24-Nov-2009 12:47:24 Central Standard Time DATE_GMT=Tuesday, 24-Nov-2009 18:47:24 GMT LAST_MODIFIED=Tuesday, 24-Nov-2009 12:47:20 Central Standard Time USER_NAME=RWATKINS SSI_ROOT=/QSYS.LIB/RWATKINS.LIB/ SSI_DIR=/ SSI_FILE=printenv.pgm
- Six Steps to write an ILE C CGI program
- 8-steps metrics program - an introduction to metrics
- Write a C program to find the parity of an unsigned integer
- Write an Efficient C Program to Reverse Bits of a Number
- Six Simple Steps to High Quality Coding
- A good blog about how to write an Hadoop MapReduce program in Python
- How to Debug C Program using gdb in 6 Simple Steps
- Final Steps to Writing an Essay
- How to Write An Email
- Write a program to pratice ATA command
- How to write a simple shell program
- Write a C program to print all permutations of a given string
- Android Lesson Six: An Introduction to Texture Filtering
- Six simple steps scientists can take to avoid having their work misrepresented
- [转]How to load an AutoLISP program
- How to write a Linux virus in 5 easy steps
- 7 Steps to Write Your Own Custom Rule using FXCOP
- Steps to write a simple batch bat file
- form表单的各种input的submit传值
- AS3.0 俄罗斯方块
- VS2008 下 ACE / TAO 的编译 for windows
- 习题10.9
- Item9: Never call virtual functions during construction or destruction
- Six Steps to write an ILE C CGI program
- Spring 和 Hibernate的集成
- Java 俄罗斯方块
- 泛型2010-05-10
- Android中Activity共享变量的另一方法:Application context
- 8.2 进程控制_进程标识符
- Session设置失效(转帖备忘)
- Hibernate 一对一主键单向关联
- 有关PBX应用和交互语音应答系统的方案