Skip to main content

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.

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.

What version of runtime are you using?


What version of runtime are you using?

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?


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?

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?


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?

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


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.

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.


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.

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


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

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


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

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.


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.

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?


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?

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


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

OK I finally got it work with Curl on the sites that will not work with the program.

What is the best way to determine what the issue is?


OK I finally got it work with Curl on the sites that will not work with the program.

What is the best way to determine what the issue is?

'finally got it to work with cURL' -- I read that as, you changed things around with cURL until it worked.

So, the first order question is:  What did you change from your initial cURL-only attempt until the successful version?


'finally got it to work with cURL' -- I read that as, you changed things around with cURL until it worked.

So, the first order question is:  What did you change from your initial cURL-only attempt until the successful version?

I was not outputting the actual XML data I wanted to upload into the command line i.e. "xml-content", which is why I was getting the XML error.

However, the structure of the POST command is exactly the same as I use in the cobol program, so I don't know why the Curl post works but the program doesn't, especially as the program works at some other sites OK