Highlighted
josephgilbat Frequent Contributor.
Frequent Contributor.
166 views

Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Hi Friends,

I got error as "Bad Request - Invalid Content Length" error when logic execute XML IMPORT TEXT.

I attached below AuthResponse.xml which was generated in my directory...  Please advise me how do i resolve this?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>
st</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Content Length</h2>
<hr><p>HTTP Error 400. There is an invalid content length or chunk length in the request.</p>
</BODY></HTML>

 

Attached my full program below. I am not sure whether i am doing it correct. My requirement is to pass the user name and password to the web service thru variable  'Doc-Authentication' and i should get response into variable Doc-response from webservice.

 

Identification division.
Program-id. Test.
Data division.
Working-storage section.
01 Doc-Authentication.
02 Doc-User Pic X(13) value 'testing'.
02 Doc-Pwd Pic X(09) value '123456'.
01 Doc-response.
02 Doc-token pic X(80).

01 request-payload usage pointer.
01 response-payload usage pointer.
01 response-status pic 9(3) value zero.
01 response-status-2 pic 9(3) value zero.
01 response-len pic s9(4).
01 request-len pic s9(4).
01 a-single-char pic x.

copy "lixmlall.cpy".

01 Desired-SOAP-Action.
05 filler pic x(10) value 'SOAPAction'.
05 filler pic x value x"00".
05 filler pic x(90) value
'"http://harlandfs/ECM/Services/Search/ExecuteSearch"'.
05 filler pic x value x"00".

01 Post-Address pic x(63) value
"https://px-demo.avcm.esvccenter.com/services/wse/WebSearch
- ".asmx".
01 Content-Type pic X(25) value "text/xml; charset=utf-8".
linkage section.
01 http-response pic x(100).

procedure division.
main.
stop 'AuthrequestF2C.xsl'
stop 'AuthResponseF2C.xsl'.
XML INITIALIZE.
if not XML-OK go to z.

XML EXPORT FILE
Doc-Authentication
"Authrequest.xml"
"Doc-Authentication".

if not XML-OK go to z.

XML EXPORT TEXT
Doc-Authentication
request-payload
response-len
"Doc-Authentication".
if not XML-OK go to z.

call "NetInit"
giving
response-status.

call "NetSetSSLCA" using "ca-bundle.crt".

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

set address of http-response to response-payload.

display "Response: ", response-status.

if not response-status = 0
call "NetGetError" using response-payload response-len
giving response-status-2
set address of http-response to response-payload
display "Error! ", response-status
display "Error message: ", http-response(1:response-len)
call "NetFree" using response-payload
go to z
end-if.

XML FREE TEXT
request-payload.

if response-payload = NULL
display "Error: NULL pointer returned", line 10, blink
accept a-single-char prompt
go to z
end-if.

XML PUT TEXT
response-payload
response-len
"Doc-response"
"AuthResponse.xml".
if not XML-OK go to z.

XML IMPORT TEXT
Doc-response
response-payload
response-len
"AuthResponse.xml".
if not XML-OK go to z.

call "NetFree"
using
response-payload.

call "NetCleanup".

z.
copy "lixmltrm.cpy".
display "finished.", line 20 position 5.
accept a-single-char prompt tab.
stop run.
copy "lixmldsp.cpy".

 

0 Likes
16 Replies
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

What is the value of request-len at the time of the POST? Does that match the length of request-payload?

---
Martin Turner
Product Support Engineer
Micro Focus
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Also, I just wanted to let you know that after execute my program , i got below files in my directory.

Authrequest.xml

===============

<?xml version="1.0" encoding="UTF-8"?>
<doc-authentication xmlns:xtk="http://microfocus.com/xml-extensions/symbol-table/"><doc-user>testing </doc-user><doc-pwd>123456</doc-pwd></doc-authentication>

Doc-response

================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Content Length</h2>
<hr><p>HTTP Error 400. There is an invalid content length or chunk length in the request.</p>
</BODY></HTML>

 

0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Thanks Martin for quick response! request-len value is blank and request-payload value has 5166252
so, request-len and request-payload does not match.
Please explain me in detail why that should match. what is the root cause for this?
0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

In the XML EXPORT TEXT statement you are using response-len instead of request-len. So the length of request-payload is being put in the wrong item.

---
Martin Turner
Product Support Engineer
Micro Focus
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

That is correct! Thanks Martin, I did the changes,
below logic executed and got generated Doc-response.xml with only one line as "Bad Request". Any issues in my below code?
XML IMPORT TEXT
Doc-response
response-payload
response-len
"AuthResponse.xml".
if not XML-OK go to z.
0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

That looks like an error returned from the web service. Check what you are sending is what the web service is expecting. Is the content type correct etc.

---
Martin Turner
Product Support Engineer
Micro Focus
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Also, i am getting run time error as below
Response: 000
Status: +0012
Error: 12[2] - data item -not found

[12] Called from line 105 in Test.acu(Test.acu), compiled compiled 20191010
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

No, below content type declaration i got from microfocus sample program(TempConvert.cbl)

01 Content-Type pic X(25) value "text/xml; charset=utf-8".

why this Content-Type need in my program? what is use of content-type?
0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

The Content-Type entity header is used to indicate the media type of the resource. In requests, the client tells the server what type of data is actually sent. Is the web service expecting that content type? Have you tested this request with SoapUI?

You need to make sure you make all necessary changes to the 'TempConvert.cbl' sample so you are sending a valid request that your web service is expecting.

---
Martin Turner
Product Support Engineer
Micro Focus
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

SOAP UI response xml as below.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><AuthTicket xmlns="http://harlandfs/ECM/Services/Search/"><AuthenticatedTicket>n2c67021-fcb2-45e2-ao21-61ed45afb4c4</AuthenticatedTicket></AuthTicket></soap:Header>


my program xml request below and got response "Bad request". as i am new to this area, just please advise me anything i am missing.?

<?xml version="1.0" encoding="UTF-8"?>
<doc-authentication xmlns:xtk="http://microfocus.com/xml-extensions/symbol-table/"><doc-user>sparak.tester</doc-user><doc-pwd>Passw0rd2</doc-pwd></doc-authentication>
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Soap header is missing in my program? How do i implement?
0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

You already set the SOAPAction header in your program. It looks like the information in the XML being sent might not what the web service expects. Can you compare the request data you successfully used in SOAPUI to what is being sent in your program?

 

I tested directly with CURL and received the same 'bad request'

 

Spoiler

C:\temp>curl -X POST -v -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction: 'http://harlandfs/ECM/Services/Search/ExecuteSearch'" -d @Authrequest.xml https://px-demo.avcm.esvccenter.com/services/wse/WebSearch.asmx

Note: Unnecessary use of -X or --request, POST is already inferred.

*   Trying 12.152.198.21...

* TCP_NODELAY set

* Connected to px-demo.avcm.esvccenter.com (12.152.198.21) port 443 (#0)

* schannel: SSL/TLS connection with px-demo.avcm.esvccenter.com port 443 (step 1/3)

* schannel: checking server certificate revocation

* schannel: sending initial handshake data: sending 192 bytes...

* schannel: sent initial handshake data: sent 192 bytes

* schannel: SSL/TLS connection with px-demo.avcm.esvccenter.com port 443 (step 2/3)

* schannel: failed to receive handshake, need more data

* schannel: SSL/TLS connection with px-demo.avcm.esvccenter.com port 443 (step 2/3)

* schannel: encrypted data got 3609

* schannel: encrypted data buffer: offset 3609 length 4096

* schannel: sending next handshake data: sending 126 bytes...

* schannel: SSL/TLS connection with px-demo.avcm.esvccenter.com port 443 (step 2/3)

* schannel: encrypted data got 6

* schannel: encrypted data buffer: offset 6 length 4096

* schannel: SSL/TLS connection with px-demo.avcm.esvccenter.com port 443 (step 2/3)

* schannel: encrypted data got 45

* schannel: encrypted data buffer: offset 45 length 4096

* schannel: SSL/TLS handshake complete

* schannel: SSL/TLS connection with px-demo.avcm.esvccenter.com port 443 (step 3/3)

* schannel: stored credential handle in session cache

> POST /services/wse/WebSearch.asmx HTTP/1.1

> Host: px-demo.avcm.esvccenter.com

> User-Agent: curl/7.55.1

> Accept: */*

> Content-Type: text/xml; charset=utf-8

> SOAPAction: 'http://harlandfs/ECM/Services/Search/ExecuteSearch'

> Content-Length: 204

* upload completely sent off: 204 out of 204 bytes

* schannel: client wants to read 102400 bytes

* schannel: encdata_buffer resized 103424

* schannel: encrypted data buffer: offset 0 length 103424

* schannel: encrypted data got 355

* schannel: encrypted data buffer: offset 355 length 103424

* schannel: decrypted data length: 326

* schannel: decrypted data added: 326

* schannel: decrypted data cached: offset 326 length 102400

* schannel: encrypted data buffer: offset 0 length 103424

* schannel: decrypted data buffer: offset 326 length 102400

* schannel: schannel_recv cleanup

* schannel: decrypted data returned 326

* schannel: decrypted data buffer: offset 0 length 102400

< HTTP/1.1 400 Bad Request

< Cache-Control: private

< Content-Type: text/html

< X-AspNet-Version: 4.0.30319

< X-UA-Compatible: IE=EmulateIE9

< Date: Thu, 10 Oct 2019 14:43:15 GMT

< Set-Cookie: TS01fa9ced=015c4be0c9f0f945d13cfdee7ec259ffc53f2d7910caf20b066e200e1d8b27cc40d44d9043; Path=/

< Transfer-Encoding: chunked

Bad Request* schannel: client wants to read 102400 bytes

* schannel: encrypted data buffer: offset 0 length 103424

* schannel: encrypted data got 34

* schannel: encrypted data buffer: offset 34 length 103424

* schannel: decrypted data length: 5

* schannel: decrypted data added: 5

* schannel: decrypted data cached: offset 5 length 102400

* schannel: encrypted data buffer: offset 0 length 103424

* schannel: decrypted data buffer: offset 5 length 102400

* schannel: schannel_recv cleanup

* schannel: decrypted data returned 5

* schannel: decrypted data buffer: offset 0 length 102400

* Connection #0 to host px-demo.avcm.esvccenter.com left intact

 

---
Martin Turner
Product Support Engineer
Micro Focus
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Martin,
Based on below my info, will you able to get clue and help me on right direction?

I called Soap UI https://px-demo.avcm.esvccenter.com/services/wse/WebSearch.asmx

and got below request result.,

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.soapui.org/sample/">
<soapenv:Header />
<soapenv:Body>
<sam:login>
<username>sparak.tester</username>
<password>Passw0rd2</password>
</sam:login>
</soapenv:Body>
</soapenv:Envelope>


and response i got below.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action>
<wsa:MessageID>urn:uuid:c0c571df-d346-4853-9aae-1606b159a14f</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:49b79a70-4cc9-4915-ac14-839380dca857</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-6b99f8f0-0019-451b-ace3-1e0f310d18c3">
<wsu:Created>2019-10-10T15:13:54Z</wsu:Created>
<wsu:Expires>2019-10-10T15:18:54Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://www.soapui.org/sample/login.</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
0 Likes
josephgilbat Frequent Contributor.
Frequent Contributor.

Re: Error - "Bad Request - Invalid Content Length" in Acucobol XML IMPORT TEXT logic.

Other UI tool gives below response ,Just fyi.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><AuthTicket xmlns="http://harlandfs/ECM/Services/Search/"><AuthenticatedTicket>a2c65021-fcb2-45e2-ad21-61ed45afb4c4</AuthenticatedTicket></AuthTicket></soap:Header>
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.