There are two options to create an object of type CL_HTTP_CLIENT:
Create by destination: A HTTP destination is pre-created in the SM59 transaction, where the information about the authentication and the service URI for the REST service access is stored.
The factory method CL_HTTP_CLIENT=>CREATE_BY_DESTINATION is used in this case to instantiate the ABAP HTTP object.
Create by URL: All required connection datails are specified on object construction, i.e. without any link to a destinat
DATA: lo_http_client TYPE REF TO if_http_client,
lv_service TYPE string.
*-------------------------------------------------------------------------------*
***This service returns the count of the entityset
lv_service = 'http://server.company.com:port/sap/opu/odata/SAP/*SRV/*Set/$count
*** Use CL_HTTP_CLIENT to consume the OData service using the method "create_by_url"
cl_http_client=>create_by_url(
EXPORTING
url = lv_service
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
*** Call the following method to autheticate the user/password and client for the remote connection.
CALL METHOD LO_HTTP_CLIENT->AUTHENTICATE(
EXPORTING
CLIENT = '200'
USERNAME = '*'
PASSWORD = '*'
LANGUAGE = 'E'
)
**** Send the request
lo_http_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2 ).
*** Receive the respose
lo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).
*** Read the result
CLEAR lv_result .
lv_result = lo_http_client->response->get_cdata( ).
write: lv_result.
ion.
The factory method CL_HTTP_CLIENT=>CREATE_BY_URL is used to in this case to instantiate the ABAP HTTP object.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
24 | |
21 | |
13 | |
12 | |
9 | |
8 | |
8 | |
8 | |
8 |