Code: Alles auswählen.
DATA: o_client TYPE REF TO if_http_client,
lv_http_status TYPE i,
lv_status_text TYPE string,
response_content TYPE string,
lv_uri TYPE string.
TRY.
" Create HTTP client based on destination
CALL METHOD cl_http_client=>create_by_destination
EXPORTING
destination = 'TEST_DESTINATION'
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( ).
RETURN. " Exit if there's an error
ENDIF.
" Setting specific path or adding parameters to the URL
lv_uri = '/this/could/be/your/endpoint'.
o_client->propertytype_logon_popup = abap_false.
o_client->request->set_header_field( name = '~request_uri' value = lv_uri ).
" Make a GET request
o_client->request->set_method( if_http_request=>co_request_method_get ).
o_client->send( timeout = if_http_client=>co_timeout_default ).
o_client->receive( ).
" Get the HTTP status and response content
o_client->response->get_status( IMPORTING
code = lv_http_status
reason = lv_status_text ).
response_content = o_client->response->get_cdata( ).
" Displaying the response code and content for debugging
WRITE: / 'HTTP Status:', lv_http_status.
WRITE: / 'Response:', response_content.
CATCH cx_root INTO DATA(lx_error).
" Handle exception
WRITE: / lx_error->get_text( ).
ENDTRY.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
sap_koun
Wie hast du das gemacht?
Folgende Benutzer bedankten sich beim Autor IHe für den Beitrag:
a-dead-trousers