Skip to Content
avatar image
Former Member

HTTP_COMMUNICATION_FAILURE when using Leonardo API from api.sap.com in ABAP

Hi Experts,

I am trying to use Leonardo API of image classification in ABAP, but on the receive method of lo_http_client, I am facing http_communication_failure. Do I need to expose/open any port in the system to access that URL of API?

URL: https://sandbox.api.sap.com/ml/imageclassifier/inference_sync

Code:

DATA: lo_http_client TYPE REF TO if_http_client.

DATA: response TYPE string.

CALL METHOD cl_http_client=>create_by_url EXPORTING url = 'https://sandbox.api.sap.com/ml/imageclassifier/inference_sync' IMPORTING client = lo_http_client EXCEPTIONS argument_not_found = 1 plugin_not_active = 2 internal_error = 3 OTHERS = 4. IF sy-subrc <> 0. ENDIF. lo_http_client->request->set_method('POST'). lo_http_client->request->set_header_field( name = 'content-type' value = 'multipart/form-data; boundary=---011000010111000001101001' ). lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ). lo_http_client->request->set_header_field( name = 'APIKey' value = ' ' ). DATA: l_xstring TYPE xstring. DATA: binary_tab TYPE STANDARD TABLE OF x255. DATA: file_length type i. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = ' ' filetype = 'BIN' IMPORTING filelength = file_length TABLES data_tab = binary_tab. CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' EXPORTING input_length = file_length IMPORTING buffer = l_xstring TABLES binary_tab = binary_tab EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. ENDIF. lo_http_client->request->append_cdata( `-----011000010111000001101001` && cl_abap_char_utilities=>cr_lf && `Content-Disposition: form-data; name="files"; filename=" ";` && cl_abap_char_utilities=>cr_lf && cl_abap_char_utilities=>cr_lf ). lo_http_client->request->append_data( l_xstring ). lo_http_client->request->append_cdata( cl_abap_char_utilities=>cr_lf && `-----011000010111000001101001--` ).

CALL METHOD lo_http_client->send

EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 http_invalid_timeout = 4

OTHERS = 5.

IF sy-subrc = 0.

CALL METHOD lo_http_client->receive

EXCEPTIONS http_communication_failure = 1 http_invalid_state = 2 http_processing_failed = 3 OTHERS = 5.

ENDIF.

IF sy-subrc <> 0.

ENDIF.

response = lo_http_client->response->get_cdata( ).

WRITE: 'response: ', response.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers