Highlighted
Absent Member.
Absent Member.
873 views

[archive] httpRequest and cgi

[Migrated content. Thread originally posted on 09 November 2005]

I am busy with an application which needs to use the httpRequest object to call a cobol program residing on a webserver using cgi and passing values back and forth
Is this possible and how will the cobol cgi program read data and pass data back ?

I have tried this with a standard cgi program, and I always get a gateway error.

ie - cobol program

01 input-form is external-form.
02 input-data pic x(1) is identified by 'testout'.

accept input-form.
move 1 to input-data.
display input-form.
stop run.


ie - asp page using javascript to call remote object

function showSickNote(theForm, theLineNo)
{
url = 'webdays.acu?testout=1';
loadXMLDoc(url);
alert(testout);
}
var req;
function loadXMLDoc(url)
{
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("POST", url, false);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("POST", url, false);
req.send();
}
}
}

function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText + "\nState:" +req.readyState + "\nCode:" + req.status);
}
}
}

//-->
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] httpRequest and cgi

Have you registered the acu extension with IIS so that it knows to execute webdays.acu using the wrun32.exe on the server? Check out the ACUCOBOL-GT Guide to the Internet manual A Programmer's Guide to the Internet
Version 7

Chapter 4: Launching Applications on a Web Server With CGI
Chapter 4.7 Configuring the Web Server
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] httpRequest and cgi

Thanks for the reply, I had forgotton the display statement in the cobol, I have another problem, I am trying to return xml back to the asp page and the request always comes back as null even though the responseback has the xml info in a string,
it seems like the response it not getting processed as xml by the cobol program ???

eg
asp page

url = 'webdays.cgi?ldate-f=' + lvDateFrom + '&ldate-t=' + lvDateTo + '&ltype=' + lvType + '&lsick=' + lvSick + '&daysout=0&messageout=N';
loadXMLDoc(url);

function loadXMLDoc(url)
{
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, false);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, false);
req.setRequestHeader("Content-Type", "text/xml");
req.send();
}
}
}

function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
responseback = req.responseText;
response = req.responseXML.documentElement;

lvDays = response.getElementsByTagName('daysout')[0].firstChild.data;
lvMessage = response.getElementsByTagName('messageout')[0].firstChild.data;

alert(responseback + '\ndays:' + lvDays + '\nmessage:' + lvMessage);

} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText + "\nState:" +req.readyState + "\nCode:" + req.status);
}
}
}


cobol program

01 INPUT-FORM
IS EXTERNAL-FORM.
03 INPUT-DATE-FROM PIC 9(10) IDENTIFIED BY "ldate-f".
03 INPUT-DATE-TO PIC 9(10) IDENTIFIED BY "ldate-t".
03 INPUT-TYPE PIC X(5) IDENTIFIED BY "ltype".
03 INPUT-SICK PIC X(1) IDENTIFIED BY "lsick".
03 INPUT-DAYS PIC Z(3).Z(3)- IS IDENTIFIED BY "daysout".
03 INPUT-MESSAGE PIC X(50) IS IDENTIFIED BY "messageout".

01 OUTPUT-FORM
IS EXTERNAL-FORM IS IDENTIFIED BY "return.xml".
03 DAYS-OUT PIC Z(3).Z(3)- IS IDENTIFIED BY "daysout".
03 MESSAGE-OUT PIC X(50) IS IDENTIFIED BY "messageout".

LINKAGE SECTION.

SCREEN SECTION.

******************************************************************
PROCEDURE DIVISION.
Main Section.

ACCEPT INPUT-FORM.

IF INPUT-DATE-FROM NOT = 0
MOVE "Success" TO INPUT-MESSAGE MESSAGE-OUT
MOVE 111 TO INPUT-DAYS DAYS-OUT
ELSE
MOVE "Failed" TO INPUT-MESSAGE MESSAGE-OUT
MOVE 9999 TO INPUT-DAYS DAYS-OUT
END-IF.


return-xml template file.



%%daysout%%
%%messageout%%
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] httpRequest and cgi

The display external form formats http headers. It is likely that you'll want to control the headers as you are sending an XML stream versus a http stream. If you want the output to be in XML format use the runtime configuration variable, CGI_CONTENT_TYPE.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] httpRequest and cgi

Hi,

Thanks a lot, it now works like a charm, the trick was to set the environment in the WEBDAYS.ACU program, I was under the impression from the help files that if the extension of the template was .xml then the headers would be correct, but it seems this is not the case. The possibility's are now endless using the AJAX engine to have live communication with the web server from the client with out having to post the page every time.

10/10 to acucorp for this new technology being able to work.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.