handling body

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
RINALDI_V
Posts: 13
Joined: Fri Jun 14, 2024 10:03 am

handling body

Post 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 :)
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: handling body

Post by Scott Klement »

Sure thing. What is the question?
RINALDI_V
Posts: 13
Joined: Fri Jun 14, 2024 10:03 am

Re: handling body

Post 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;
Attachments
Screenshot 2024-06-27 185249.png
Screenshot 2024-06-27 185249.png (77.62 KiB) Viewed 14151 times
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: handling body

Post 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?
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: handling body

Post 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;             
RINALDI_V
Posts: 13
Joined: Fri Jun 14, 2024 10:03 am

Re: handling body

Post by RINALDI_V »

Thank you very much, this way it works!
Post Reply