Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report YBC_HTTP_SERVER_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ybc_http_client_test.
* data declarations
DATA: client TYPE REF TO if_http_client.
DATA:
host TYPE string VALUE 'http://xamp:8081', " <==== URL der BSP Applikation
errortext TYPE string.
DATA:
uri TYPE string,
subrc TYPE i,
version TYPE i,
request TYPE REF TO if_http_request.
DATA res_data TYPE xstring.
DATA res_cdata TYPE string.
DATA:buffer TYPE xstring,
conv TYPE REF TO cl_abap_conv_in_ce,
buf TYPE TABLE OF tab512 WITH HEADER LINE,
bytes_read TYPE i,
fname TYPE string VALUE 'c:\temp\000.html'.
DEFINE m_err_exit.
if sy-subrc <> 0.
call method client->get_last_error
importing
code = subrc
message = errortext.
exit.
endif.
END-OF-DEFINITION.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = host
IMPORTING
client = client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
m_err_exit.
client->request->set_header_field( name = '~request_method'
value = 'POST' ).
*CALL METHOD client->request->set_form_field
* EXPORTING
* name = '$get'
* value = 'checked'.
CALL METHOD client->send
*exporting timeout = timeout
EXCEPTIONS http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
m_err_exit.
CALL METHOD client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
m_err_exit.
*CALL METHOD client->response->get_data
* RECEIVING
* data = res_data.
CALL METHOD client->response->get_cdata
RECEIVING
data = res_cdata.
m_err_exit.
CALL METHOD client->close
EXCEPTIONS
http_invalid_state = 1
OTHERS = 2.
m_err_exit.
Folgende Benutzer bedankten sich beim Autor Tron für den Beitrag:
Tommy Nightmare