|
I'm trying to have 1 program to respond to requests from a ws session or from the web(cgi-bin). How can you tell which way the program was called (ws session or web) so you can respond appropriately?
I'm not sure what a "ws session" is. Web service? Workstation?If you mean workstation, you can check the REQUEST_METHOD environment variable. IF it's not set, it's a workstation session. If it's set, it's called via CGI (or a regular program that's deliberately trying to look like it's calling via CGI, which is often done when testing CGI code.)
Here's a proof of concept: H DFTACTGRP(*NO) ACTGRP('TEST') BNDDIR('QC2LE') * * I use the following (by preference) instead of QtmhGetEnv * (but QtmhGetEnv() would've also worked) D getenv PR * extproc('getenv') D varname * value options(*string) * * I use the following (by preference) instead of QtmhWrStout * (but QtmhWrStout would've also worked) D stdout s * import('_C_IFS_stdout') D fputs PR 10I 0 ExtProc('_C_IFS_fputs') D string * value options(*string) D stream * value D fflush PR 10U 0 ExtProc('_C_IFS_fflush') D stream * value D ptr s * D reqmeth s 10A varying D data s 500A varying D wait s 1A /free ptr = getenv('REQUEST_METHOD'); if (ptr = *NULL); DSPLY ('Not a CGI job!') ' ' wait; else; reqmeth = %str(ptr); data = 'Content-type: text/html' + x'0d250d25'; fputs(data: stdout); data = '<html><body><h1>' + 'This is a CGI program called with the ' + reqmeth + ' request method.' + '</h1></body></html>' +x'0d25'; fputs(data: stdout); fflush(stdout); endif; return; /end-freeIf you meant "web service" rather than workstation, the solution is somewhat similar. Read an environment variable again, but this time look for the CONTENT_TYPE variable. If it's set to text/xml, then it has sent you an XML document (and therefore is likely a webservice) if it sends Application/x-www-form-urlencoded, then it's a regular web page (HTML form).
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.