Code: Alles auswählen.
TRY.
" API URL
DATA(lv_url) = |https://www.rapdiapi.com|.
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 = 'X-RapidAPI-Host'
value = 'airport-info.p.rapidapi.com' ).
o_client->request->set_header_field( name = 'X-RapidAPI-Key'
value = '7217e89939msh998319a5fa4b773p107fc2jsne56a3276d142' ).
"set_timout
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.