Search code examples
jsonhttppostabap

ABAP CL_HTTP_CLIENT->request->set_data failed 400 if data >= 1024 bytes


I'm using a POST request with a JSON through CL_HTTP_CLIENT. Faced the following situation:

When xstrlen( jsonx ) <= 1024, I get http_rc = 200 (OK).

When xstrlen( jsonx ) > 1024, I get http_rc = 400 (Incorrect data given).

Profile parameter icm/HTTP/max_request_size_KB = 102400.

Tried to send the same data not via SAP client, with result 200 (OK).

Instead of client->request->set_data I used client->request->set_сdata, the result is similar, as soon as the string size exceeds 1024 bytes, I get a 400 response.

What could be the error, am I somehow filling in the data incorrectly?

Can there be size limits for request data?

Code:

  DATA: client TYPE REF TO if_http_client.

  cl_http_client=>create_by_destination( EXPORTING
     destination = 'z_test'
     IMPORTING
       client = client ).

  client->propertytype_logon_popup = if_http_client=>co_disabled.
  client->request->set_version( if_http_request=>co_protocol_version_1_1 ).
  client->request->set_method( if_http_request=>co_request_method_post ).
  client->request->set_header_field( name = 'Accept'        value = 'application/json' ).
  client->request->set_header_field( name = 'Content-Type'  value = 'application/json' ).
  client->request->set_header_field( name = 'Authorization' value = |Bearer TokenValue| ).

  DATA: json TYPE string.
  DATA: jsonx TYPE xstring.

  json = '{"data":['.
  json = json && '{"login":"login1","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
  json = json && '"groups":[{"path":"path"}]},'.
  json = json && '{"login":"login2","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
  json = json && '"groups":[{"path":"path"}]},'.
*  json = json && '{"login":"login3","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
*  json = json && '"groups":[{"path":"path"}]},'.
  json = json && '{"login":"login4","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
  json = json && '"groups":[{"path":"path"}]},'.
  json = json && '{"login":"login5","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
  json = json && '"groups":[{"path":"path"}]},'.
  json = json && '{"login":"login7","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
  json = json && '"groups":[{"path":"path"}]}],'.
  json = json && '"partial_sync":false,"chief_sync":false,"notify_users":false,"with_whitelist":false}'.
  
  jsonx = cl_abap_codepage=>convert_to(
           source = json
           codepage = 'UTF-8' ).

  DATA(json_lenx) = xstrlen( jsonx ).
  client->request->set_data( data = jsonx
                             offset = 0
                             length = json_lenx ).

*  DATA(get_jsonx) = client->request->get_cdata( ).

  CALL METHOD client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      http_invalid_timeout       = 4
      OTHERS                     = 5.
  IF sy-subrc <> 0.
    RAISE connection_error.
  ENDIF.
  CALL METHOD client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.
  IF sy-subrc = 0.
    DATA: http_rc TYPE sy-subrc.
    client->response->get_status( IMPORTING code = http_rc ).
    l_xml = client->response->get_cdata( ).
  ENDIF.
  client->close( ).

Solution

  • The problem was at SM59 settings. Connection settings of compression must be Inactive. There is no error if compression inactive.

    Compression Settng