Anda di halaman 1dari 2

*&---------------------------------------------------------------------*

*& Form SEND_DATA


*&---------------------------------------------------------------------*
* Send data to MQ by URL
*----------------------------------------------------------------------*
FORM send_data USING iv_xml_string TYPE string.

DATA: l_httpclient TYPE REF TO if_http_client,


l_xml_response TYPE REF TO cl_xml_document,
lv_response_string TYPE string,
lv_response TYPE string,
lv_code TYPE i.

cl_http_client=>create_by_destination( EXPORTING
destination = 'MQSI_REST'
IMPORTING
client = l_httpclient ).

l_httpclient->request->set_header_field( EXPORTING
name = 'Content-Type'
value = 'text/plain; charset=utf-8' ).

l_httpclient->request->set_header_field( EXPORTING
name = 'Accept'
value = 'text/xml, text/html' ).

l_httpclient->request->set_header_field( EXPORTING
name = 'X-MessageType'
value = 'TaxReport' ).
l_httpclient->request->set_header_field( EXPORTING
name = '~request_method'
value = 'POST' ).

l_httpclient->request->set_cdata( EXPORTING
data = iv_xml_string
offset = 0 ).

l_httpclient->send( EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2 ).

l_httpclient->receive( EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).

l_httpclient->response->get_status( IMPORTING code = lv_code reason =


lv_response ).
lv_response_string = l_httpclient->response->get_cdata( ).
l_httpclient->close( ).
IF lv_code = 200.
MESSAGE text-s01 TYPE 'S'.
ELSE.
WRITE lv_response_string.
MESSAGE lv_response TYPE 'E'.
ENDIF.

ENDFORM. " SEND_DATA

Anda mungkin juga menyukai