HTTP/1.1 400 Bad Request

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
KKT
Posts: 8
Joined: Thu Apr 28, 2022 8:05 am

HTTP/1.1 400 Bad Request

Post by KKT »

Hi Scott,
I am using HTTPAPI Ver 1.42 released 2020-10-12 .
We are trying to send data to Azure from AS400. We are getting 'HTTP/1.1 400 Bad Request' error .
Please find below the code snippet.Could you please tell me where I am going wrong?

http_setOption( 'content-type' : 'application/json' );
http_debug(*On: '/tmp/httpdebug.txt');
http_xproc( HTTP_POINT_ADDL_HEADER : %paddr(addSpecialHeaders) );

Monitor;
rc = http_req( 'POST'
: %Trim( Url )
: '/tmp/Test.txt'
: *Omit
: *Omit
: %Trim( w#Payload ) );
If rc <>1;
errorMsg = http_error( xErrorNo );
EndIf;
On-Error;
errorMsg = http_error( xErrorNo );
http_comp('Error! xErrorNo: ' + %char(xErrorNo) +
' errorMsg: ' + errorMsg );

EndMon;

PaddSpecialHeaders...
P B
DaddSpecialHeaders...
D PI
D headersToAdd 32767a varying
*

headersToAdd = 'x-functions-key:' + 'uniquekey'
+ CRLF ;

Return;
PaddSpecialHeaders...
P E

W#PayLoad contains below information.
{"control": { "business_unit":"specialty professions","business_segment":"lawyers","business_subsegment":"small/large","program":"xxxx","product":""},"accounting":{"business_information": {"name":"My Business Name"},"addresses":[{"type":"Billing","address_line": "750 3rd Ave Ave-test","city": "New York","state": "NY","country_code": "US","postal_code":"100172703"}],"email":"kkt@XXX.com","phone_number":"3179416104"}, "trace_id":"XXX000000000"}

Error-Log is as below:
SetError() #49: SSL_protocol: Unknown protocol 596
Protocol Used:
http_persist_req(POST) entered.
http_long_ParseURL(): entered
do_oper(POST): entered
There are 0 cookies in the cache
POST /api/postchanges HTTP/1.1
Host: azfun-xxx-dev-sys-xxxsync.azurewebsites.net
User-Agent: http-api/1.24
Content-Type: application/json
Content-Length: 467
l9spXXXXT/XXXXXXX/8S5F3l75tl2XxxxTO0ByjQZOIFbU
senddoc(): entered
{"control": { "business_unit":"specialty professions","business_segment":"XXs","business_subsegment":"small/large","p..."}
recvresp(): entered
HTTP/1.1 400 Bad Request
Content-Length: 0
Connection: close
Date: Tue, 31 May 2022 12:06:30 GMT
SetError() #13: HTTP/1.1 400 Bad Request
recvresp(): end with 400
recvdoc parms: identity 0
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
SetError() #13: HTTP/1.1 400 Bad Request
http_close(): entered

Thanks & Regards,
KKT
KKT
Posts: 8
Joined: Thu Apr 28, 2022 8:05 am

Re: HTTP/1.1 400 Bad Request

Post by KKT »

Hi Scott,
I was sending wrong authorization key I mean.. without the header 'x-functions-key'. When i added it, it worked :).

Thanks & Regards,
Karthika Talluri
Post Reply