winHttp

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"ioits1web01/.../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

  • Verified Answer

    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

  • 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