2024 Aug 08 9:47 AM - edited 2024 Aug 08 10:19 AM
I have an API that contains a request that uses x-www-form-urlencoded as body data type .. i noticed that when i use set_body_data the client proxy automaticly set the content-type to json so that won't work .. so i had to remove the request body before the execute and use the mo_http_client to set the custom content type and set_form_fields but that also didn't work .. any ideas how to send POST request with x-www-form-urlencoded data using client_proxy ?
as an example
data(lo_request) = mo_http_client->request.
lo_request->set_content_type( 'application/x-www-form-urlencoded' ).
lo_request->set_form_fields( value #( ( name = 'grant_type' value = 'password' ) ) ).
mo_client_proxy->create_resource( zaf_if_types=>gcs_resource_names-pets
)->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-post
)->execute()
Notice : The used framework is iwbep client proxy rest
abap client proxy
abap odata client proxy samples
Hi
To send a POST request with x-www-form-urlencoded data using the iwbep client proxy, follow these steps:
Remove Default Request Body: Ensure no default body data is set before configuring the request.
Set Content Type and Form Fields:
DATA(lo_request) = mo_http_client->request.
lo_request->set_content_type( 'application/x-www-form-urlencoded' ).
lo_request->set_form_fields( VALUE #( ( name = 'grant_type' value = 'password' ) ) ).
Execute Request:
DATA(lo_response) = mo_client_proxy->create_resource( zaf_if_types=>gcs_resource_names-pets )
->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-post )
->execute( ).
This approach should work if mo_http_client and mo_client_proxy are correctly initialized
Note:If you face issues, verify that the mo_http_client and mo_client_proxy are configured properly and that you are using the correct HTTP method and resource names.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
57 | |
11 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.