*&---------------------------------------------------------------------*
*& Report ZSAP_TEST_48
*&
*&---------------------------------------------------------------------*
*&
*& text: get response contents from url
*& fm: HTTP_GET
*&---------------------------------------------------------------------*
REPORT zsap_test_48.
TYPES: BEGIN OF text ,
line(256),
END OF text .
DATA: gt_response TYPE TABLE OF text WITH HEADER LINE .
DATA: gt_response_header TYPE TABLE OF text WITH HEADER LINE .
DATA: g_status(3) TYPE c ,
g_statustext(128) TYPE c ,
g_length TYPE i .
PARAMETERS: url(50) TYPE c LOWER CASE DEFAULT 'http://www.baidu.com'.
PARAMETERS: dest LIKE rfcdes-rfcdest DEFAULT 'SAPHTTP'.
CALL FUNCTION 'HTTP_GET'
EXPORTING
absolute_uri = url
* REQUEST_ENTITY_BODY_LENGTH =
rfc_destination = dest
* PROXY =
* PROXY_USER =
* PROXY_PASSWORD =
* USER =
* PASSWORD =
blankstocrlf = 'Y'
* TIMEOUT =
IMPORTING
status_code = g_status
status_text = g_statustext
response_entity_body_length = g_length
TABLES
* REQUEST_ENTITY_BODY =
response_entity_body = gt_response
response_headers = gt_response_header
* REQUEST_HEADERS =
* EXCEPTIONS
* CONNECT_FAILED = 1
* TIMEOUT = 2
* INTERNAL_ERROR = 3
* TCPIP_ERROR = 4
* DATA_ERROR = 5
* SYSTEM_FAILURE = 6
* COMMUNICATION_FAILURE = 7
* OTHERS = 8
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT gt_response_header .
WRITE / gt_response_header-line .
ENDLOOP.
SKIP 2 .
LOOP AT gt_response .
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
IN gt_response-line WITH ' '.
WRITE / gt_response-line .
ENDLOOP.
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = dest
EXCEPTIONS
OTHERS = 0.