Sending HTTP response code in ILE RPG
We (Tim Wyers and I) just spend a few hours to find out how to send an HTTP response code from an ILE RPG CGI program on System i. From the documentation provided by IBM, it looked like the QzhbCgiUtils API was the way to go, but we ended up with a this very simple solution: If you just write Status: 404 Not found to standard out, the HTTP server will translate that into the HTTP/1.1 404 Not found response code.
d WriteStdout pr ExtProc('QtmhWrStout')
d 65535a Const Options(*Varsize) //data variable
d 9b 0 Const //length of data
d 16a Options(*Varsize) //error struct
d/Copy Qsysinc/Qrpglesrc,Qusec
/free
WriteStdout('Status: 404 Not Found' + X'15': 25: Qusec);
WriteStdout('Content-type: text/html'+X'15'+X'15': 27: Qusec);
WriteStdout('<html\><body>Page not found</body></html>': 29: Qusec);
Return;
/end-free