This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

httppost

I have a program that uses HTTPPOST to upload an XML data file to a REST web service using the form-data content type.

This was working OK but now on some systems it has started to report a NULL response and I cannot determine why.

The equivalent web page upload works OK via Chrome and does not give any errors so dismissing Op sys, machine configuration etc.

I run the post with the code shown below

Any ideas as to why I get a null response on some machines and not others?

01 post-address pic x(150).
78 Content-Type value 'multipart/form-data; boundary="12345"'.

01 request-payload usage pointer.
01 response-payload usage pointer.

01 response-len pic s9(8).
01 request-len pic s9(8).

01 response-status pic 9(3) value zero.

01 import-xml-request pic x(180).
01 parser-handle usage handle.
01 xml-content pic x(99999999).
01 form-data pic x(99999999).

linkage section.
01 response-data pic x(5555).

initialize request-payload request-len.
set request-payload to address of form-data.

call "NetInit" giving response-status.

CALL "NetSSLVerifyPeer" USING SSL-verifypeer-flag
GIVING response-status.


call "HttpSetResponseHeader" using 0
GIVING response-status.

call "C$XML" using CXML-WRITE-STRING
PARSER-HANDLE
xml-content.

call "C$XML" using CXML-PARSE-FILE
import-xml-request.
move return-code to parser-handle

string "--12345"
H"0D0A"
'Content-Disposition: form-data; name="uid"'
H"0D0A"
H"0D0A"
"USERNAME"
H"0D0A"
"--12345"
H"0D0A"
'Content-Disposition: form-data; name="pwd"'
H"0D0A"
H"0D0A"
"PASSWORD"
H"0D0A"
"--12345"
H"0D0A"

"Content-Disposition: form-data; name="
""""
"uploadfile"
""""
"; filename="
""""
UPLOADFILENAME
""""
H"0D0A"
* "Content-Type: text/xml"
"Content-Type: multipart/form-data"
H"0D0A"
H"0D0A"
xml-content
H"0D0A"
"--12345--"
delimited by "$" into form-data.

call "HttpPost" using
Post-Address
Content-Type
request-payload
request-len
response-payload
response-len
giving response-status.

set address of response-data to response-payload.

  • 0  

    What version of runtime are you using?

    ---

    Martin Turner

    Senior Technical Support Engineer

    Rocket Software

  • 0 in reply to   

    Some where it has stopped working are 9.2.4 and some that are working 10.0.1

    If it is the runtime why would it have worked OK previously?

  • 0   in reply to 

    I was thinking that it was an issue that was fixed in 10.4.0 but that was relating to HTTPGET when I checked.

    Have you tried inspecting the response via Wireshark (or something similar), before it reaches the COBOL program, to see if the server is actually sending back the correct response?

    You could also try sending the request via another tool like Insomnia to see if the same happens there.

    Is anything logged on the server that could explain the null response?

    ---

    Martin Turner

    Senior Technical Support Engineer

    Rocket Software

  • 0   in reply to 

    You could try increase the timeout values for the RMNET. Maybe the request is taking too long on some occasions and causing a timeout.

    HttpSetConnectTimeout - https://bit.ly/3MBZuEh

    HttpSetTimeout - https://bit.ly/3LnQ4fe

    ---

    Martin Turner

    Senior Technical Support Engineer

    Rocket Software

  • 0

    The tool that is the most direct analog to RMNet is the curl command line tool.  This is due to the fact that RMNet uses libcurl.  Using curl might help you diagnose the issue more easily, and a failing curl example would be easier if you seek technical support from the web service vendor.

  • 0

    Do you know the value of response-status when the response-payload is null?

  • 0 in reply to 

    The response status is 7

    I converted the post into a curl command which I think is correct i.e.

    curl.exe --trace trace.txt -k POST -H "multipart/form-data; boundary=12345" --data "--12345/r/n'Content-Disposition: form-data; name=uid/r/n/r/nUSERNAME/r/n--12345/r/n'Content-Disposition: form-data; name=pwd/r/n/r/nPASSWORD/r/n--12345/r/nContent-Disposition: form-data; name=uploadfile; filename=DISKFILENAME/r/nContent-Type: multipart/form-data/r/n/r/nxml-content/r/n--12345--" URL

    When I run it gives the following error

    curl: (6) Could not resolve host: POST
    <?xml version="1.0" encoding="UTF-8"?>
    <Error Message="The http(s) request should be multipart encoded." />

  • 0 in reply to 

    If the response status is 7, then for some reason the request is being blocked, either on the client machine, or at the server.  

    Do a search on "curl error code 7" and see if any of the suggestions help.

    As far as the command line, I would place the request payload data in a file.  That will make the command line much more manageable.

  • 0 in reply to 

    I seem to have got a bit further trying the upload with cURL but it is now giving me the following error

    curl: (6) Could not resolve host: POST
    <?xml version="1.0" encoding="UTF-8"?>
    <DMSSubmissionReport>
    <Error Message="XML error: Error on line 1: Content is not allowed in prolog." />
    </DMSSubmissionReport>

    I have checked the XML upload file and it all looks intact and in fact uploaded via a web page loader in chrome successfully

    Any thoughts?

  • 0   in reply to 

    Error 6 seems like a DNS issue on your client. But then you get a response from the server too? So it actually has resolved the domain to IP?

    The XML error looks like the same issue discussed here - stackoverflow.com/.../fatal-error-11-content-is-not-allowed-in-prolog

    ---

    Martin Turner

    Senior Technical Support Engineer

    Rocket Software