Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
guilherme_frisoni
Contributor
0 Kudos
17,446

here is a simple code to load an HTML page into a internal table:

" Local Vars

DATA: lo_client  TYPE REF TO if_http_client,

       lc_url     TYPE string,

       lc_content TYPE string,

       lt_html    TYPE TABLE OF string.

" Set html page to load

lc_url = 'http://www.sap.com'.

" Create the HTTP client

CALL METHOD cl_http_client=>create_by_url

   EXPORTING

     url    = lc_url

   IMPORTING

     client = lo_client

   EXCEPTIONS

     OTHERS = 1.

IF sy-subrc IS NOT INITIAL.

   " Error

   EXIT.

ENDIF.

" Set the Request type to GET

lo_client->request->set_header_field( name  = '~request_method'

                                       value = 'GET' ).

" Make the call

lo_client->send( ).

" Receive the Response Object

CALL METHOD lo_client->receive

   EXCEPTIONS

     http_communication_failure = 1

     http_invalid_state         = 2

     http_processing_failed     = 3

     OTHERS                     = 4.

IF sy-subrc IS NOT INITIAL.

   " Error

   EXIT.

ENDIF.

" Get the response content in Character format

lc_content = lo_client->response->get_cdata( ).

" Split content by lines in an internal table

SPLIT lc_content AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_html.

" From here you can parse you html code from table lt_html

It´s done.

3 Comments
Labels in this area