*&---------------------------------------------------------------------*
*& Report RSWF_TEST_HTTP *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
report zrswf_test_http .
*- begin of internal data
type-pools: swfxc, icon.
data: l_http_client type ref to if_http_client.
data: l_url type string.
data: l_code type sy-subrc.
data: l_code_string type string.
data: l_message_string type string.
data: lt_http_fields type tihttpnvp.
data: l_http_field_wa type ihttpnvp.
data: l_char_header(40) type c.
data: l_body_string type string.
*- end of internal data
*-----------------------------------------------------------------------
*- Create the HTTP-Client
*-----------------------------------------------------------------------
call method cl_http_client=>create_by_url
exporting
url = l_url
* PROXY_HOST = l_proxy_host
* PROXY_SERVICE = l_proxy_service
importing
client = l_http_client
exceptions
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4.
if sy-subrc <> 0.
exit.
endif.
l_http_client->request->set_method( method = if_http_entity=>co_request_method_post ).
* CALL METHOD l_http_client->request->set_header_field
* EXPORTING
* name = 'Content-Type'
* value = 'APPLICATION/XML;charset=gbk'.
data lv_json_data type string.
l_http_client->request->set_cdata( lv_json_data ).
*-----------------------------------------------------------------------
*- send the http post
*-----------------------------------------------------------------------
call method l_http_client->send
exceptions
http_communication_failure = 1
http_invalid_state = 2.
if sy-subrc <> 0.
call method l_http_client->get_last_error
importing
code = l_code
message = l_message_string.
call method l_http_client->close.
return.
endif.
*-----------------------------------------------------------------------
*- receive the result of http post
*-----------------------------------------------------------------------
call method l_http_client->receive
exceptions
http_communication_failure = 1
http_invalid_state = 2.
if sy-subrc <> 0.
call method l_http_client->get_last_error
importing
code = l_code
message = l_message_string.
call method l_http_client->close.
return.
endif.
*-----------------------------------------------------------------------
*- print the results
*-----------------------------------------------------------------------
call method l_http_client->response->get_status
importing
code = l_code.
*-- get the http header fields
call method l_http_client->response->get_header_fields
changing
fields = lt_http_fields.
loop at lt_http_fields into l_http_field_wa.
endloop.
*- get the body
l_body_string = l_http_client->response->get_cdata( ).
HTTP Client Code
于 2023-10-19 10:05:23 首次发布