Highlighted
Absent Member.
Absent Member.
6252 views

[archive] HTTP Request.

[Migrated content. Thread originally posted on 01 March 2004]

I'm looking for an example of sending and receiving an html request in cobol.
The purpose is to send a request to a sms server like 'http://sms.server.com?id=my-id&telnr=+310000000&message=test'.
then to receive de answer of the server which is a short html page with a status (which i want to check in my the cobol program).
If possible an example with c$socket. Thx.
0 Likes
16 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

This seems pretty close to one of the sms examples we have. Like:


           DISPLAY STANDARD         GRAPHICAL WINDOW
                   TITLE            "ACUCOBOL-GT SMS Demo"
                   SIZE             63.5
                   LINES            31
                   CONTROL          FONT IS CNTL-FONT
                   BACKGROUND-LOW.

          DISPLAY WEB-BROWSER      VISIBLE = 0
                  EVENT PROCEDURE  SMS-EVENT
                  HANDLE           IN WB-SMS.
           ...
           STRING  "https://telenormobil.no/ums/smapi/send"
                   "?sender=aphonenumberhere"
                   "&password="
                   URL-PWD          DELIMITED BY SPACE
                   "&recipients="
                   RECEP-PHONE      DELIMITED BY SPACE
                   "&sid=yoursubscriptionidhere"
                   "&messageType=text"
                   "&content="
                   EDITOR-STRING    DELIMITED BY SIZE
                   "&responsType=text" DELIMITED BY SIZE
                   INTO             SMS-URL.
           MODIFY  WB-SMS           VALUE = SMS-URL.


Is this what you are looking for?
Ask your local support for the entire program, smsdemo.cbl.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

While it should be technically doable, I would not recommend using C$SOCKET for this, as it would be a heavy task to accomplish.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

This should be working (using the web-browser) for the send part, but I don't see how to read the result of the returning (answer) html page in my program.
Is this also possible. Thx
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

Good point. To read results, I suppose the web control won't do. Then you would either use the Windows API or c$socket. Perhaps the API is the better option here as well. I do in fact have an example of that as well if you are interested.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

I've tried it with the c$socket The problem here is to send the request. If I use a string with format ' GET http://sms.server.com?id=my-id&telnr=+310000000&message=test HTTP/1.1 (crlf)' and send it to the server, there will be no response. When I send 2 times 'list' ?? the server response with an html-string with the message ' invalid method in request'. So here it looks like I can receive an answer but not send a request. Perhaps there is a solution for sending this request. Thx.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

There's a Microsoft Knowledge Base article that covers this issue with a code example in visual basic. It makes a call to the windows api URLDownloadToFile function in URLMON.DLL.
Article is here: http://support.microsoft.com/default.aspx?scid=KB;en-us;q244757

Also, Wininet.dll api library has useful funtions for opening and reading url resources. They can buffer html before saving and I believe can download embedded images and scripts. Visual Basic samples of wiinet functions located here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;185519
http://support.microsoft.com/default.aspx?scid=kb;en-us;259100&Product=vb6
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

Originally posted by Ed1
If I use a string with format ' GET http://sms.server.com?id=my-id&telnr=+310000000&message=test HTTP/1.1 (crlf)' and send it to the server, there will be no response.


I am no expert of http programming, but it makes sense to me that you fail here. Essentially, what the http says at a lower level is to communicate via port 80. Thus, also implying GET and PUT is not the way to deal with this using c$socket.

I suggest you stop this path, it is just going to be too heavy, and at any rate, why reinvent the wheel?

Attached you will find an example from my talk at the 2001 developers conference. I won't warrant that the url is still valid, but the technique using the API should be okay.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

I haven't tried using it with Acucobol, but in the past I've used the Microsoft XMLHTTP object to get data from other web pages.

See this URL for some details (in VB of course):

http://www.4guysfromrolla.com/webtech/110100-1.shtml
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

The VB example for the Microsoft XMLHTTP object looked really useful so I did a quick translation to acucobol. Example is attached.


030204 IDENTIFICATION DIVISION.
       PROGRAM-ID.     MSXMLHTTP.
       AUTHOR.         Dan Maltes.
       DATE-WRITTEN.   3/02/04.
       REMARKS.  Acucobol example of using Microsoft's
                 XMLHTTP Object to Get data from other web pages.
                 Derived from VB example by Richard Love found here:
                 [url]http://www.4guysfromrolla.com/webtech/110100-1.shtml[/url]

                 Definition file MSXML50.DEF generated from the
                 Microsoft XML v5.0 component library.
                 
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
       COPY "MSXML50.DEF".
            .
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 MS-XML-OBJECT                HANDLE OF @XMLHTTP.
       77 ESCAPE-CODE                  PIC 9(04) VALUE 0.
       77 WS-URL                       PIC X(50) VALUE SPACES.
       77 WS-RESPONSE                  PIC X(64000) VALUE SPACES.
       77 WS-STATUS                    PIC 9(04) VALUE 0.
       01 COM-OBJECT-ERROR-INFO        VALUE SPACES.
           05 COM-OBJ-ERR-TYPE         PIC X(20).
           05 COM-OBJ-ERR-SOURCE       PIC X(50).
           05 COM-OBJ-ERR-DESCRIPTION  PIC X(200).
       77 COM-OBJ-ERR-ACTION           PIC X(30).

          COPY "ACTIVEX.DEF".

       LINKAGE SECTION.
       SCREEN SECTION.
        01 MAIN-SCREEN.
           05 LABEL, TITLE "URL: (use [url]http://[/url] prefix)"
              LINE 2 COL 5.
           05 URL-ENT, ENTRY-FIELD
              VALUE WS-URL
              LINE + 1.5 COL 5 SIZE 55.
           05 LABEL, TITLE "Response:"
              LINE + 3 COL 5.
           05 RESPONSE-DISPLAY, ENTRY-FIELD
              VALUE WS-RESPONSE
              LINE + 2, COL 5 SIZE 55
              LINES 15, MAX-TEXT 64000
              VSCROLL-BAR
              READ-ONLY.
           05 OK-BUTTON, PUSH-BUTTON
              TITLE "&Get"
              LINE + 17, COL 17
              OK-BUTTON.
           05 EXIT-BUTTON, PUSH-BUTTON
              TITLE "E&xit"
              COL + 5
              CANCEL-BUTTON.

       PROCEDURE DIVISION.
       DECLARATIVES.
       COM-OBJECT-ERROR SECTION.
           USE AFTER EXCEPTION ON OBJECT.
       PROCESS-COM-OBJECT-ERROR.
           CALL "C$EXCEPINFO" USING ERROR-INFO, COM-OBJ-ERR-SOURCE,
               COM-OBJ-ERR-DESCRIPTION.
           |Add more code here to handle COM errors...

       END DECLARATIVES.

       MAIN-LOGIC SECTION.
       ML-BEGIN.
           CREATE @XMLHTTP HANDLE IN MS-XML-OBJECT.
           DISPLAY STANDARD GRAPHICAL WINDOW
              TITLE "Microsoft XML HTTP Demo"
              SIZE 65
              LINES 30
              BACKGROUND-LOW.
           DISPLAY MAIN-SCREEN.
           PERFORM UNTIL ESCAPE-CODE = 27
              ACCEPT MAIN-SCREEN
              ACCEPT ESCAPE-CODE FROM ESCAPE KEY
              IF ESCAPE-CODE = 13
                 |Good idea to check for properly formed url first
                 |ie. [url]http://[/url] prefix
                 MODIFY MS-XML-OBJECT @Open("GET", WS-URL, 0)
                 MODIFY MS-XML-OBJECT @Send()
                 INITIALIZE WS-STATUS
                 INQUIRE MS-XML-OBJECT @Status IN WS-STATUS
                 |Full list of status values here:
                 |[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_pro_sz_0h4k.asp[/url]
                 IF WS-STATUS = 200
                    INITIALIZE WS-RESPONSE
                    INQUIRE MS-XML-OBJECT @responseText IN WS-RESPONSE
                    DISPLAY MAIN-SCREEN
                 END-IF
              END-IF
           END-PERFORM.
           DESTROY MS-XML-OBJECT.
       ML-END.
           EXIT PROGRAM.
           STOP RUN.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

Hi all,
I agree that is not necessary to implement the full HTTP protocol
in a Cobol program, but this task is so simple that using C$SOCKET has some advantages:
-it's portable
-it's not dependant from third part software
-it's funny to program c$socket (IMHO) 🙂

The sample from DanM is really what I am able to obtain in AcuCobol without any COM object and with few lines of code.

For instance, the attached program is an example of using C$SOCKET and CGI from Acucobol.
I attach only the objects in debug, because of this is part of a Totem project and if you don't use Totem is a bit tricky to set it up in order to compile, but it's feasible.
The main proupose of this program is to put a file from the local
client to a web server via a POST method. The POST method calls
a POST-HANDLER that's another Cobol program.
Anyway it shows also the full HTTP conversation, so you can also
personalize it as you want (for instance with your GET request),
and the program will show the result.

To use it (in the original way):
-run http-agent.acu
-set up "Nome Server" as http://www.acucorp.it
-leave the "Post Handler" field unchanged
-pick up a text file in the field "Nome File" (remember to use only a TXT file, since the trasmission is done without any encoding)
-check the "anteprima" check-box to see the HTTP conversation
-click on "Invia!"


If you want to try a GET, you simply :
-fill the "nome server" with your server
-select a file for "Nome File" (it is only because the program check
if the file exist)
-click on "Invia", in the Preview panel change POST with GET and insert the full URI ( GET http://sms.server.com?id=my-id&teln...00&message=test), then leave unchanged the rest (also if it's not formal correct),
anyway after the click on OK the program will show the full HTTP response from the server. You'll be able to look for your message here.

This won't work if you're behind a proxy, but is necessary only a little change (you have to open the socket with the proxy insetad of opening it with the target machine).

Hope this helps Ed1, and if anyone need the source, just ask.

Bye
Luca
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] HTTP Request.

ooops
I forgot the attach
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.