使用事物码 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.
运行之后,如果一切成功,会自动弹出 ABAP 调试器:
如上图所示,双击第 42 行的变量 rv_data:
将 View 从 Fast Display 切换成 HTML Browser,即可看到通过 ABAP 代码请求回来的百度首页:
更多Jerry的原创文章,尽在:"汪子熙":
网友评论