In ABAP Make an API HTTP Request. / ABAP HTTP Request

Photo by Barn Images on Unsplash
DATA: lv_http_dest TYPE rfcdest VALUE 'SAP_SCPI_ConEmp'.
DATA: o_client TYPE REF TO if_http_client.
TRY.
cl_http_client=>create_by_destination(
EXPORTING destination = lv_http_dest
IMPORTING client = o_client).
o_client->request->set_method( if_http_request=>co_request_method_post ).
o_client->send( ).
o_client->receive( ).
o_client->response->get_status( IMPORTING
code = lv_http_rc
reason = lv_reason ).
IF lv_http_rc = 200.
DATA(lv_json) = o_client->response->get_cdata( ).
WRITE lv_json.
ELSE.
WRITE: / 'Error: ', lv_http_rc.
ENDIF.
o_client->close( ).
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.

The other Method(HACK)!:

DATA(lv_url) = |https://www.google.de/|.
DATA: o_client TYPE REF TO if_http_client.
TRY.
cl_http_client=>create_by_destination(
EXPORTING url = lv_url
IMPORTING client = o_client).
o_client->request->set_method( if_http_request=>co_request_method_post ).
o_client->send( ).
o_client->receive( ).
o_client->response->get_status( IMPORTING
code = lv_http_rc
reason = lv_reason ).
IF lv_http_rc = 200.
DATA(lv_json) = o_client->response->get_cdata( ).
WRITE lv_json.
ELSE.
WRITE: / 'Error: ', lv_http_rc.
ENDIF.
o_client->close( ).
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store