PARAMETERS: url TYPE swc_value.
DATA: l_url
TYPE string.
TYPE-POOLS: swfxc, icon.
DATA: l_http_client
TYPE REF TO if_http_client.
DATA: l_code
TYPE sy-subrc.
DATA: lt_http_fields
TYPE tihttpnvp.
DATA: lt_header_fields TYPE tihttpnvp .
DATA: l_message_string
TYPE string.
DATA: l_body_string
TYPE string.
l_url = url.
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.
* MESSAGE ID
SY-MSGID TYPE 'S' NUMBER SY-MSGNO
* WITH
SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
* into
l_message_string.
ENDIF.
APPEND VALUE #( name = 'Content-Type' value =
'application/json' ) TO lt_header_fields.
APPEND VALUE #( name = 'accept' value = 'application/json' )
TO lt_header_fields.
l_http_client->request->set_header_fields( fields =
lt_header_fields ).
l_http_client->request->set_method(
if_http_request=>co_request_method_get ) .
cl_http_utility=>set_request_uri(
EXPORTING
request =
l_http_client->request " HTTP
Framework (iHTTP) HTTP Request
uri = l_url " URI String (in the
Form of /path?query-string)
).
CALL METHOD
l_http_client->send
EXCEPTIONS
http_communication_failure
= 1
http_invalid_state = 2.
IF sy-subrc <>
0.
ENDIF.
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.
ENDIF.
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.
l_body_string =
l_http_client->response->get_cdata(
).
CALL METHOD
l_http_client->close.
No comments:
Post a Comment