First you need to setup your HTTP server to allow CGI:
On the as400 the HTTP server jobs run in the subsystem QHTTPSVR. You will see groups of jobs running for each HTTP Server instance (each configured HTTP Server).
To gain access to the confirguration of the HTTP server you can use the green screen command Work with HTTP Configuration (WRKHTTPCFG), but I much prefer the browser based HTTP Admin client.
To use this you must have started you HTTP Server admin instance using STRTCPSVR SERVER(*HTTP) HTTPSVR(*ADMIN). This will start the QHTTPSVR subsystem if it is not active, and then start the ADMIN instance.
In your browser, Go to http://youras400name:2001/. You will need to login with an authorised as400 logon at this point.
At the AS400 tasks screen click on IBM HTTP Server. At this point you need to either select an existing HTTP server, or setup a new HTTP Server using the wizard.
Click the Add a Directory to the Web task. Click CGI programs, and click next.
Enter the serving directory (as400 program library), and clicked next,
enter Alias (url to be used to invoke the as400 CGI program), click next.
Restart the HTTP server.
Now you can serve CGI. Here is a sample RPG CGI Program
Create a binding directory for the CGI service program:
CRTBNDDIR, and add QHTTPSVR / QZHBCGI (*SVRPGM) to it.
H bnddir('CGI') * New Line Constant DCRLF C CONST(X'0D25') C EVAL OUTTXT = 'Content-Type: text/html'+CRLF+CRLF C EXSR OutputText C EVAL OUTTXT = 'Hello World C EXSR OutputText C SETON LR C RETURN C OutputText BEGSR C ' ' CHECKR OUTTXT OUTLEN C CALLB 'QtmhWrStout' C PARM OUTTXT C PARM OUTLEN C PARM ERRCDE C ENDSR
xx
This would get invoked by something such as a URL like http://your-server/your-cgi-bin/helloworld
and as400 Bobs your uncle!
Greetings!
ReplyDeleteThere is a free product from IBM called CGIDEV2 that makes CGI programming for the AS400 very cookie-cutter, and has abundant instructions, tutorials and examples.
http://www-922.ibm.com/en?
Bob Cozzi and Brad Stone also offer (for some $) tools and guidance on creating
Cozzi: http://www.rpgxtools.com/
Stone: http://www.bvstools.com/erpg/
Tom,
ReplyDeleteIve heard about CGIDEV2, though I must admit to never having had a look at it. Shame on me.
Ill try and get some time to review these
cheers mate
Colin.W
I cant imagine anything uglier than coding CGIs with RPG. Alone how CGIs were handled on webservers is a performance nightmare.
ReplyDeleteBut i like this blog, i didnt know it before and being in the iSeries and Java space for about some years, it might be an interessting read.
Marc Logemann
http://www.logemann.org