2023 Dec 29 6:07 AM
Dear All,
I am new to this. I have one requirement to pass data in urlencoded format. I am using one url to retrieve token. In this URL, I am passing data using IF_HTTP_CLIENT with content type application/x-www-form-urlencoded in ABAP program. My program is working fine in postman. In postman, I am passing content type in Header and certain fields in Body part of postman ( i.e. grant_type, client_id, client_secret ) and it is working ok in postman, But when I am passing it in ABAP. it is giving me 404 error. I
I am passing below data:
lv_body = 'grant_type=client_credentials&client_id=ABCD&client_secret=ABCDEFGHIJK≻ope=openid'.
LO_HTTP_CLIENT->PROPERTYTYPE_LOGON_POPUP = LO_HTTP_CLIENT->CO_DISABLED.
LO_HTTP_CLIENT->REQUEST->SET_METHOD( 'POST' ).
LO_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD(
NAME = 'Content-Type'
VALUE = 'application/x-www-form-urlencoded' ).
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = LV_BODY
IMPORTING
BUFFER = LV_BODYX.
CALL METHOD LO_HTTP_CLIENT->REQUEST->SET_DATA( LV_BODYX ).
Regards,
Archana
2023 Dec 29 9:08 AM
404 means page not found, so it's probably an issue with the URL (what you didn't post).
Do an ICF Client trace (SICF > menu) to know the exact HTTP request sent, compare with Postman, and tell us what is different between the 2 HTTP requests.
2024 Jan 04 9:51 AM
Try passing the parameters as form fields instead of body data.
cl_http_client=>create_by_url( EXPORTING url = ws_url IMPORTING client = DATA(http_client) ).
http_client->request->set_method( if_http_request=>co_request_method_post ).
http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded' ).
http_client->request->set_form_field( name = 'client_id' value = 'ABCD' ).
http_client->request->send( ).
I currenlty have an url-encoded WebService which I pass the parameters this way and works fine.
2024 Jan 04 10:01 AM
Hi sandra.rossi & javier_alonso,
Thanks for your replies. I found an issue with URL which i am pssing to create http_client. After correcting it is working fine.
Thanks once again.
Regards,
Archana