Page 1 of 1
handling body
Posted: Thu Jun 27, 2024 4:03 pm
by RINALDI_V
Good evening, I would like to ask a question about managing the body in a POST request for a token.
I am using the function http_string('POST': url: SendStr: 'application/json');
URL :http://<localhost>/tse_webapi/auth/token
SendStr: SendStr = '{"grant_type":"password","username":"<xxx>"'
+ ',"password":".<xxx>"}';
Thank you in advance

Re: handling body
Posted: Thu Jun 27, 2024 4:40 pm
by Scott Klement
Sure thing. What is the question?
Re: handling body
Posted: Thu Jun 27, 2024 5:03 pm
by RINALDI_V
Sorry, how can I include the Body information (as shown in the attached screenshot) in my request? The reference request is
URL = '
http://192.168.16.119:81/tse_webapi/auth/token';
SendStr = '{"grant_type":"password","username":"admin"'
+ ',"password":".Admin01"}';
monitor;
response = http_string('POST': url: SendStr: 'application/json');
on-error;
msg = http_error();
endmon;
Re: handling body
Posted: Thu Jun 27, 2024 10:26 pm
by Scott Klement
You are including it in your request.
Did you mean to encode it as URL-encoded form data instead of as a JSON document, like the Postman screenshot?
Re: handling body
Posted: Thu Jun 27, 2024 10:34 pm
by Scott Klement
I think you want something like this:
Code: Select all
dcl-s userid varchar(128) inz('admin');
dcl-s password varchar(128) inz('.Admin01');
dcl-s url varchar(1000);
url = 'https://192.168.16.119/tse_webapi/auth/token';
SendStr = 'grant_type=password'
+ '&username=' + http_urlEncode(userid)
+ '&password=' + http_urlEncode(password);
monitor;
response = http_string('POST'
: url
: SendStr
: 'application/x-www-form-urlencoded');
on-error;
msg = http_error();
endmon;
Re: handling body
Posted: Wed Jul 10, 2024 10:47 am
by RINALDI_V
Thank you very much, this way it works!