0

I want to send a PUT request using cl_http_client to a Flask endpoint

CL_HTTP_CLIENT=>CREATE_BY_URL(
EXPORTING
  URL                = MY_URL
  SSL_ID = 'ANONYM'
IMPORTING
  CLIENT             = AO_HTTP_CLIENT
EXCEPTIONS
  ARGUMENT_NOT_FOUND = 1
  PLUGIN_NOT_ACTIVE  = 2
  INTERNAL_ERROR     = 3
  ).

IF SY-SUBRC IS NOT INITIAL.
  "Error handling
ENDIF.


AO_HTTP_CLIENT->REQUEST->SET_METHOD( 'PUT' ).

AO_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD( NAME  = 'Content-Type' VALUE = 'multipart/form-data').

AO_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD( NAME = 'Authorization'
                                       VALUE = 'Basic Y292ZXN0cxxxxxxx3Zlc3Ryb19kZW1v').


AO_HTTP_CLIENT->REQUEST->SET_FORM_FIELD( NAME = 'VAR1' VALUE = '1' ).
AO_HTTP_CLIENT->REQUEST->SET_FORM_FIELD( NAME = 'VAR2' VALUE = '2' ).


AO_HTTP_CLIENT->SEND( ).

The code is 500 and the reason is BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

jpsstack
  • 1,221
  • 4
  • 18
  • 29
  • 1
    In fact, the error comes from between the SAP system and the Flask endpoint. Possibly a proxy? (PROXY_* parameters of `CREATE_BY_URL`) Otherwise, could you make your request to Flask endpoint work from Postman or such software? – Sandra Rossi Jul 13 '22 at 17:31
  • Does this answer your question? [Bad Request error when calling HTTP\_POST?](https://stackoverflow.com/questions/24322222/bad-request-error-when-calling-http-post) – Suncatcher Jul 14 '22 at 10:08
  • also check https://stackoverflow.com/questions/43996153/https-communication-failure-abap and https://stackoverflow.com/questions/39333573/invalid-request-parameter-create-and-sending-envelopes – Suncatcher Jul 14 '22 at 10:11
  • The problem is that the data ends up in the query string and not in the request body. But apparently you can use flask to read the query string via request.args. – jpsstack Jul 15 '22 at 06:09
  • In order to diagnose this problem, I would try to figure out what HTTP request actually arrives at the end-point, and compare it to a request doing the same thing which the endpoint accepts. Unfortunately this question contains neither information. – Philipp Jul 15 '22 at 08:35

0 Answers0