The following code is producing this message: {"statusCode": 400, "body": "Not JSON"}
D HTTPAPI_VERSION...
D C CONST('1.23')
D HTTPAPI_RELDATE...
D C CONST('2008-04-24')
I have verified that the JSON is formatted properly and is present in the request variable at the time of the http call.
The logs on the web-service show there is nothing in the body of the request. Am I using the correct procedure call for this?
request = '{JSON stuff here}' ;
t_Endpoint = 'http://theendpoint.com';
// Notify httpapi of the routine to use to add headers
http_xproc( HTTP_POINT_ADDL_HEADER
: %paddr(addSpecialHeaders)
: %addr(authorizationToken) );
response = 'tmp/TEST.json';
rc = http_url_post( t_Endpoint
: %addr(request)
: %len(%trim(request))
: %Trim(response)
: Timeout
: HTTP_USERAGENT
: 'application/json'
);
Sending JSON in the body of an HTTP request
-
- Site Admin
- Posts: 905
- Joined: Sun Jul 04, 2021 5:12 am
Re: Sending JSON in the body of an HTTP request
make sure if this is a VARYING/VARCHAR field that you are getting the address of the *DATA not the address of the length prefix.
Re: Sending JSON in the body of an HTTP request
That was the issue. Since the body JSON is fairly small I changed the variable definition to char(500) and cleared it before setting the value. Clearing shouldn't make any difference but I did it anyway.
Thank you very much.
Thank you very much.
-
- Site Admin
- Posts: 905
- Joined: Sun Jul 04, 2021 5:12 am
Re: Sending JSON in the body of an HTTP request
all you needed to do was change %addr(request) to %addr(request:*data)
no point in going back to the 1990s.
no point in going back to the 1990s.
Re: Sending JSON in the body of an HTTP request
That was it. Thanks again.