Highlighted
Contributor.
Contributor.
1336 views

In a native cobol program, I'm trying to make a web request using the WinHttp.WinHttpRequest.5.1 com object.  The process works just fine if I'm sending text to the web site:

           INVOKE WINHTTP "new" RETURNING WH.
           IF WH = NULL
              MOVE "WINHTTP Service failed to initialize" TO LOG-REC
              WRITE LOG-REC
           END-IF.
           
           MOVE "CALLING ESEC" TO LOG-REC.
           WRITE LOG-REC.
           
           INVOKE WH "Open" using
                       z"POST"
         z"http://ioits1web01/enterprisesecurity/api/Security/Validate".
                       HTTP-ESEC-VALIDATE-URL.
       ***                ws-boolfalse.
       
       ** set document type to text/json
           INVOKE WH "SetRequestHeader"  USING z"Content-type"
                                              z"text/json"
                                        RETURNING HTTP-STATUS.
           MOVE HTTP-STATUS TO HTTP-DSTATUS.
           MOVE SPACES TO LOG-REC.
           STRING "SETREQUESTHEADER RETURNED - " HTTP-DSTATUS
               INTO LOG-REC.
           WRITE LOG-REC.
       
       ** SET UP POST VARIANT
           INITIALIZE HTTP-LEN.
           INSPECT HTTP-REQ-STRING TALLYING HTTP-LEN FOR CHARACTERS
               BEFORE INITIAL LOW-VALUE.
               
           INVOKE OLEVARIANT "new" returning OV.
           IF OV = NULL
               MOVE "OLE VARIANT FAILED TO INITIALIZE" TO LOG-REC
               WRITE LOG-REC
           ELSE
               MOVE "CALLING SETSTRING" TO LOG-REC
               WRITE LOG-REC
               MOVE LENGTH OF HTTP-REQ-STRING TO HTTP-LEN
               INVOKE OV "setString" using by value HTTP-LEN
                                     BY REFERENCE HTTP-REQ-STRING
                                     RETURNING HTTP-STATUS
           END-IF.
                  
           MOVE HTTP-STATUS TO HTTP-DSTATUS.
           MOVE SPACES TO LOG-REC.
           STRING "SETSTRING RETURNED - " HTTP-DSTATUS INTO LOG-REC.
           WRITE LOG-REC.
           
           INVOKE WH "Send"  using HTTP-REQ-STRING
                             RETURNING HTTP-STATUS.
              
           MOVE HTTP-STATUS TO HTTP-DSTATUS.
           MOVE SPACES TO LOG-REC.
           STRING "ESEC SEND RETURN CODE = " HTTP-DSTATUS
              INTO LOG-REC.
           WRITE LOG-REC.
           
           INVOKE WH "getResponseText" returning WS-SSO-RETURN-MSG.

However, I need to send either XML or a JSON to the site.  I tried doing:

           INVOKE WH "SetRequestHeader"  USING z"Content-type"
                                                                                z"text/json"
                                        RETURNING HTTP-STATUS.

However, that returns an error "OLE Name not found" (80020006): Unknown name".


How can I set the content type of the outgoing data to be something other than "text/plain".


Mike

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: winHttp

Jump to solution

Hi Mike,

setRequestHeader is a method and not a property so you need to set the dispatch type before the call. You will need something like:-

     ***** Set Request Header

          invoke olesup "setDispatchType" using by value 0

          invoke ws-winhttp "SetRequestHeader" using

             z"content-type" z"application/x-www-form-urlencoded"

Regards

David

View solution in original post

0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: winHttp

Jump to solution

Hi Mike,

setRequestHeader is a method and not a property so you need to set the dispatch type before the call. You will need something like:-

     ***** Set Request Header

          invoke olesup "setDispatchType" using by value 0

          invoke ws-winhttp "SetRequestHeader" using

             z"content-type" z"application/x-www-form-urlencoded"

Regards

David

View solution in original post

0 Likes
Highlighted
Contributor.
Contributor.

RE: winHttp

Jump to solution

Bingo!  Thanks for the answer.

I'm an old mainframe cobol programmer, somewhat newer to programming in Windows and OO, so my mindset is that nary the twain shall meet.  So things like calling Windows COM objects, while straight-forward, sometimes trip me up on the details.

Thanks again!

Mike

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.