Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Retrieving HTML source code of a web page

Former Member
0 Likes
355

Hi,

I want to take the HTML source code of a web page. How can I take?

Thanks and regards,

Venkat.

1 REPLY 1
Read only

andrs_picazo
Explorer
0 Likes
308

You can do that with the class "cl_http_client".

Sample code:



DATA: http_client TYPE REF TO if_http_client .

DATA: w_string TYPE string ,
w_result TYPE string ,
r_str TYPE string .

DATA: result_tab TYPE TABLE OF string.

START-OF-SELECTION .
CLEAR w_string .
w_string = 'http://urlhost/Logs/main.asmx/SetLog'.

CALL METHOD cl_http_client=>create_by_url
EXPORTING
url                = w_string
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active  = 2
internal_error     = 3
OTHERS = 4.

CALL METHOD HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
EXPORTING
NAME = '~request_method'
VALUE = 'POST'.

CALL METHOD http_client->REQUEST->SET_FORM_FIELD
EXPORTING
NAME = 'title'
VALUE = 'Mail sistema'.

CALL METHOD http_client->REQUEST->SET_FORM_FIELD
EXPORTING
NAME = 'details'
VALUE = 'Funcion 1234'.

CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state         = 2.

CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state         = 2
http_processing_failed     = 3.
CLEAR w_result .
w_result = http_client->response->get_cdata( ).

REFRESH result_tab .
SPLIT w_result AT cl_abap_char_utilities=>cr_lf INTO TABLE
result_tab .

READ TABLE result_tab INTO r_str INDEX 2.