使用事物码 SE38,新建一个 ABAP 程序,将下列代码粘贴进去,激活:
REPORT zhttp.
DATA: so_client TYPE REF TO if_http_client.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'http://www.baidu.com'
IMPORTING
client = so_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
ASSERT sy-subrc = 0.
so_client->request->set_method( 'GET' ).
CALL METHOD so_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
ASSERT sy-subrc = 0.
CALL METHOD so_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
IF sy-subrc <> 0.
so_client->get_last_error( IMPORTING code = data(lv_code) message = data(lv_message) ).
WRITE:/ | error code: { lv_code }, text: { lv_message } |.
return.
endif.
DATA(rv_data) = so_client->response->get_cdata( ).
so_client->close( ).
BREAK-POINT.