cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Outbound HTTP POST: SAP reorders headers

770

Hi,

I have a strange problem using cl_http_client. I want to do a mulitpart POST, but SAP (maybe the ICM?) reorders the HTTP headers I add using CALL METHOD lo_multipart->set_header_field and also adds Content-Length.

So even if I add the headers in the order 1: Content-Disposition 2: Content-Type, the outgoing request will contain it in another order and Content-Length added:

1: Content-Type 2: Content-Length 3: Content-Disposition.

Using lo_multipart->suppress_content_type does not change anything either.

However, the external platform I'm interfacing with is sensitive to the order of headers, and will NOT work, if Content-Disposition is not the first header.

Is it possible to configure or turn off this behavior of SAP?

Please check the example below.

Thanks and best regards,

Tamás

ABAP Code:

...

lo_multipart = lo_http_client->request->if_http_entity~add_multipart( ).
CALL METHOD lo_multipart->suppress_content_type EXPORTING suppress = 'X'.

CONCATENATE 'form-data; name="file"; filename="' iv_filename '";' INTO lv_form_value.
*
CALL METHOD lo_multipart->set_header_field
EXPORTING
name = 'Content-Disposition'
value = lv_form_value.

CALL METHOD lo_multipart->set_content_type
EXPORTING
content_type = iv_content_type.

CALL METHOD lo_multipart->set_data
EXPORTING
data = iv_xstring.

...

Outgoing HTTP request:

--F2814BF8064476F37754F550F04B29960

Content-Type: text/html

Content-Length: 8925

content-disposition: form-data; name="file"; filename="SU53_output_passed_INC-000444_S72_20190227.html";

<html dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Report output</title> <style>table.list { border-collapse: collapse; }</style> </head> <!script!> <body bgcolor="#E8EAD8"> ... DATA

Accepted Solutions (0)

Answers (1)

Answers (1)

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes

I do not have experience with a "multipart" so excuse me if it is wrong idea. But what if you set headers with lo_http_client->request instead of lo_multipart ?

Also have you tried to use this parameter?

IF_HTTP_ENTITY~ADD_MULTIPART method with parameter SUPPRESS_CONTENT_LENGTH

instead of:

lo_multipart->suppress_content_type method

Also you can try set_header_fields instead of set_header_field. But it will probably also will be reordered 😞

Dear Tomas,

You've made my day!!! At least partly 🙂 I overlooked the "suppress_content_length" parameter, thanks for pointing that out.

As Content-Type was mandatory in the external system, I had to do another trick: add two headers into one line... this way SAP does not reorganize it :DD

Now everything works as expected: Integration of SAP and Efecte ITSM systems: https://youtu.be/N7BFkcty-XI

Have a nice day!

Cheers,

Tamás