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: 

cl_http_client is not sending query parameters in POST

bassanders
Explorer
0 Kudos
1,401

Hi everyone,

I'm having troubles with sending a HTTP request (POST).

I'm creating a HTTP POST request from an URL with a query parameter. But when I send the request the target returns with the problem that the Query parameter is not set. This is the code:

lv_url = 'https://management.azure.com/subscriptions/blablabla/' &&

'resourcegroups/blablabla/providers/microsoft.datafactory/factories/blablabla/' &&

'pipelines/blablabla/createrun?api-version=2018-06-01'.

cl_http_client=>create_by_url(

EXPORTING

url = lv_url

IMPORTING

client = lo_http_client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

others = 4

).

IF sy-subrc IS NOT INITIAL.

* Handle errors

ENDIF.

lo_http_client->request->set_method( 'POST' ).

lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/x-www-form-urlencoded').

CONCATENATE 'Bearer '

<l_token>

INTO lv_headerfield

SEPARATED BY space.

CALL METHOD lo_http_client->request->set_header_field

EXPORTING

name = 'Authorization' " Name of the header field

value = lv_headerfield. " HTTP header field value

CALL METHOD lo_http_client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3

OTHERS = 4.

CALL METHOD lo_http_client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3

OTHERS = 4.

IF sy-subrc NE 0.

CALL METHOD lo_http_client->get_last_error

IMPORTING

code = subrc

message = errortext.

WRITE: / 'communication_error( receive )',

/ 'code: ', subrc, 'message: ', errortext.

EXIT.

ELSE.

WRITE: / lv_url.

DATA(lv_string3) = lo_http_client->response->get_cdata( ).

WRITE: / lv_string3.

ENDIF.

This is the respons:

during the HTTP call the query parameter ?api-version=2018-06-01 is just not added.

Can someone help?

Regards,

Bastiaan

11 REPLIES 11

Sandra_Rossi
Active Contributor
0 Kudos
861

I'm surprised that the query parameter seems to not being sent...

Could you verify that the HTTP Trace confirms that it's sent or not sent? (SICF > Client > Recorder)

bassanders
Explorer
861

Hi,

I think I found the issue. It seems to be the length of the url. Accoring to SICF -> Client -> Recorder this request path is sent:

/subscriptions/0c73ca54-aadd-488f-85ee-3c72d2658fa4/resourcegroups/automation/providers/microsoft.datafactory/factories/plainwat

The request path is cut off on 128 charachters

Any idea how to fix this?

Bastiaan

Sandra_Rossi
Active Contributor
0 Kudos
861

Your URL is truncated.

Instead of:

DATA lv_url TYPE c LENGTH 128.

declare:

DATA lv_url TYPE string.

0 Kudos
861

Hi,

lv_url is allready declared as string

Here you can see that the field is filled correctly:

Also when I look in the Object everything looks fine:

M_HOST = management.azure.com

M_PATH = /subscriptions/0c73ca54-aadd-488f-85ee-3c72d2658fa4/resourcegroups/Automation/providers/microsoft.datafactory/factories/plainwaterADF/pipelines/ExactOnline_MD/createrun

M_QUERY = api-version=20180601

When I look in the monitoring this URL is sent:

https://management.azure.com/subscriptions/0c73ca54-aadd-488f-85ee-3c72d2658fa4/resourcegroups/autom...

So during the push to the kernel: the url is truncated

regards,

Bastiaan

0 Kudos
861

Weird. Just tried with my system. No issue, my HTTP trace shows that it transfers "?api-version=2018-06-01":

POST /subscriptions/blablabla/resourcegroups/blablabla/providers/microsoft.datafactory/factories/blablabla/pipelines/blablabla/createrun?api-version=2018-06-01 HTTP/1.0

0 Kudos
861

It gets even weirder.....

I managed to use a way to shorten the URL, but that doesn't fix the issue...

He just does not sent the Query-parameters.

regards

0 Kudos
861

Are you really sure that the ICF Client Recorder shows this?

POST /subscriptions/.../createrun HTTP/1.0

(without ?api-version=2018-06-01)

If so, you should check the SAP notes, and contact SAP Support.

0 Kudos
861

This is what is shown in ICF monitoring

It seems like he puts the Query parameters in the header, instead of the URL

grt,

Bastiaan

0 Kudos
861

That's only the path, not the query parameters. You must click the button display (glasses) > in external mode, and display the "request body". You will see POST ... HTTP/1.0 along with the query parameters (as in my previous comment).

0 Kudos
861

Hi,

That is the problem.. I did all that but you only see this when I click at the glasses and click on Request Body:

if I do not pass the query parameters at all, then indeed I see this in the recorder, but offcourse I still need to pass the parameters:

Regards,

Bastiaan

0 Kudos
861

In my test, I see the same as in your screenshot, but you don't show what is IMPORTANT (just before "HTTP/1.0", that we don't see in your screenshot). You should prefer pasting the text.