SAP ‘den rest servislere POST ve GET işlemi.

Merhaba ,

Aşağıdaki kod ile sap ‘den 3.parti yazılımlara veri aktara bilir response alabilirsiniz.

FUNCTION ZTP_HTTP_REQUEST.
*”———————————————————————-
*”*”Local Interface:
*”———————————————————————-
DATALV_RESPONSE TYPE STRING,
LV_URL TYPE STRING.

DATALV_CLIENT TYPE REF TO IF_HTTP_CLIENT.

* Set url.
LV_URL ‘http://127.0.0.1/api/test’.

* Create client.
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL(
EXPORTING
URL                LV_URL
IMPORTING
CLIENT             LV_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND 1
PLUGIN_NOT_ACTIVE  2
INTERNAL_ERROR     3
OTHERS             ).

* Set requests method. Ex ‘GET’ or ‘POST’.
LV_CLIENT->REQUEST->SET_HEADER_FIELDNAME  ‘~request_method’
VALUE ‘GET’ ).

* Set paramaters and values.
LV_CLIENT->REQUEST->SET_FORM_FIELDNAME ‘param1’ VALUE ‘value1’ ).
LV_CLIENT->REQUEST->SET_FORM_FIELDNAME ‘param2’ VALUE ‘value2’ ).

* Send requests.
CALL METHOD LV_CLIENT->SEND(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE 1
HTTP_INVALID_STATE         2
HTTP_PROCESSING_FAILED     3
OTHERS                     ).

CALL METHOD LV_CLIENT->RECEIVE(
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE 1
HTTP_INVALID_STATE         2
HTTP_PROCESSING_FAILED     3
OTHERS                     ).

* Get response.
LV_RESPONSE LV_CLIENT->RESPONSE->GET_CDATA).

WRITE LV_RESPONSE.

* Close client.<
LV_CLIENT->CLOSE).

ENDFUNCTION.

 

You may also like...

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.