cancel
Showing results for 
Search instead for 
Did you mean: 

passing URL parameters using CL_HTTP_CLIENT for POST Method

vamsixk
Active Participant
0 Kudos

I have to query an external URL to fetch some data that we have to use in our system.

Now recently the API was changed from GET to that of POST.

Earlier we had maintained the URL parameters directly in the RFC and were able to generate a successful response.

But now since the change in the API when i change the request method to post the QUERY parameters are not being passed to the Service.

For example if i my URL is "XXXX.XXXX.net/v1/oauth2/tokens?grant_type=client-credentials" the service only gets XXXX.XXXX.net/v1/oauth2/tokens. the Query parameters are being truncated by the post request.

I already checked the options in the Post

https://archive.sap.com/discussions/thread/3437183

Any other way forward? to make it work the way it was for the GET Method?

patriciachacon
Explorer
0 Kudos

How do I solve it?

former_member353872
Discoverer
0 Kudos

Hello Vamshi,

i am struck with this similar issue of passing From and To dates as parameters in HTTPS POST method call. In postman, it works fine. Any solution you got?

Thanks

Naresh J

Accepted Solutions (0)

Answers (2)

Answers (2)

The URL parameters can be passed in 2 ways. The below code will give you exactly what you want (as per your postman screenshot).

1.

lo_http_client->append_field_url(
EXPORTING
name = 'fieldname' " Field Name
value = 'fieldvalue' " Field Value
CHANGING
url = 'lv_url' " URL to which to append the field
).

2.

lo_http_client->request->set_form_field(
EXPORTING
name = 'fieldname' " Name of form field
value = 'fieldvalue' " Form field value
).

cl_http_utility=>set_request_uri( request = lo_http_client->request
uri = lv_url ).

Regards,

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos
vamsixk
Active Participant
0 Kudos

HI Horst,

Thank you for your quick reply.

This is an external service non-SAP that is being called via an RFC(Type G), which uses basic authentication via Client Credentials.

We have to provide a username and password for authenticating. And on top of that this is an outgoing HTTPS request. which we are instantiating based on the RFC destination that we have configured.

In the example we are just calling a service and displaying it. But we want to call an external service and process the response and use it in further processing.

In short is there a way to pass QUERY parameters using the class CL_HTTP_CLIENT. I know that we can pass Header parameters and form parameters via SET_HEADER_FIELD and SET_FORM_FIELD methods. But this external service uses query parameters.

This is how it looks on postman postman-query-params.png

The text highlighted in yellow are the query parameters. and are not considered as Header parameters or Form parameters.

awaiting your valuable feedback.

Kind Regards,

Vamsi