Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Passing data using application/x-www-form-urlencoded using IF_HTTP_CLIENT

archanapillai
Explorer
0 Kudos
2,630

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

3 REPLIES 3

Sandra_Rossi
Active Contributor
2,541

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.

javier_alonso
Participant
0 Kudos
2,541

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.

2,541

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