Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report Z_HTTP_REQ
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_http_req.
TRY.
*API Url
DATA(lv_url) = |https://airport-info.p.rapidapi.com/airport?iata=LAX|.
DATA: o_client TYPE REF TO if_http_client.
*Create Http Object
cl_http_client=>create_by_url( EXPORTING
url = lv_url
IMPORTING
client = o_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
IF sy-subrc <> 0.
o_client->close( ).
ENDIF.
IF o_client IS BOUND.
*set http method
o_client->request->set_method( if_http_request=>co_request_method_get ).
*set_header_fields
o_client->request->set_header_field( name = 'XXX'
value = 'XXX' ).
o_client->request->set_header_field( name = 'XXX'
value = 'XXX' ).
*set timeout
o_client->send( timeout = if_http_client=>co_timeout_default ).
* read response, http_status, payload
o_client->receive( ).
DATA: lv_http_status TYPE i,
lv_status_text TYPE string.
o_client->response->get_status( IMPORTING
code = lv_http_status
reason = lv_status_text ).
WRITE: / 'HTTP_STATUS_CODE:', lv_http_status.
WRITE: / 'STATUS_TEXT', lv_status_text.
IF lv_http_status = 200.
DATA(lv_result) = o_client->response->get_cdata( ).
WRITE: / 'Response:'.
WRITE: / lv_result.
ENDIF.
* close http connection
o_client->close( ).
ENDIF.
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.