Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ICF - Internet Communication Framework →  ICF Examples 

ABAP as HTTP Client

This example demonstrates an ICF client object.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA query TYPE string VALUE 'SAP'.
    cl_demo_input=>request( CHANGING field = query ).

    cl_http_client=>create(
      EXPORTING
        host =    'wikipedia.org'
        service = ''
      IMPORTING
        client = DATA(client)
      EXCEPTIONS
        OTHERS = 4 ).
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.

    cl_http_utility=>set_request_uri(
      request = client->request
      uri     = `/wiki/` && query ).

    client->send(
      EXCEPTIONS
        OTHERS = 4 ).
    IF sy-subrc <> 0.
      client->get_last_error(
        IMPORTING message = DATA(smsg) ).
      cl_demo_output=>display( smsg ).
      RETURN.
    ENDIF.

    client->receive(
      EXCEPTIONS
        OTHERS = 4 ).
    IF sy-subrc <> 0.
      client->get_last_error(
        IMPORTING message = DATA(rmsg) ).
      cl_demo_output=>display( rmsg ).
      RETURN.
    ENDIF.

    DATA(html) = client->response->get_cdata( ).
    cl_demo_output=>display_html( html ).

    client->close( ).

Description

The factory method CREATE of the class CL_HTTP_CLIENT is used to create a client object for the address wikipedia.org. The reference variable client of the type IF_HTTP_CLIENT points to this object. A specific request, which also contains the value of a user input, is added to the URI of the REQUEST object of the client object. The request is sent and the result is passed to the RESPONSE object of the client object. In the case in question, the HTML page produced by the requested is retrieved and displayed.


Note

The proxy setting for the HTTP client must be configured correctly in transaction SICF before this example can work.