1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
* Build Url DATA(lv_url) = |http://jsonplaceholder.typicode.com/todos/1|. * Create Client DATA lo_http_client TYPE REF TO if_http_client . cl_http_client=>create_by_url( EXPORTING url = lv_url IMPORTING client = lo_http_client EXCEPTIONS argument_not_found = 1 plugin_not_active = 2 internal_error = 3 OTHERS = 4 ). lo_http_client->request->set_content_type( 'application/json' ). * Send lo_http_client->send( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 http_invalid_timeout = 4 OTHERS = 5 ). * Receive lo_http_client->receive( EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 others = 4 ). IF sy-subrc NE 0. DATA(lv_err_string) = VALUE string( ). DATA(lv_ret_code) = VALUE sy-subrc( ). lo_http_client->response->get_status( IMPORTING code = lv_ret_code reason = lv_err_string ). MESSAGE lv_err_string TYPE 'I'. ENDIF. DATA(lv_response) = VALUE string( ). lv_response = lo_http_client->response->get_cdata( ). |