cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP issues during simple call to external API using SAP ABAP

ricky_shaw
Contributor
0 Kudos
941

Hi,

I am trying to use the API's for Airport locations. The API is from : https://airport-info.p.rapidapi.com/

I had written the code in ABAP(SE38) as below: 

In my code, I had created the  HTTP Object using cl_http_client=>create_by_url 

 

 

 Report ZAPITEST.
 
    DATA: lv_url   TYPE string,
          o_client TYPE REF TO if_http_client.

    lv_url = |https://airport-info.p.rapidapi.com/airport?iata=IAH&icao=%20| .


**Create HTTP Object
    cl_http_client=>create_by_url( EXPORTING  url = lv_url
                                  IMPORTING   client = o_client
                                  EXCEPTIONS
                                      argument_not_found = 1
                                      plugin_not_active = 2
                                      internal_error = 3
                                  OTHERS = 4 ).

    IF sy-subrc NE 0.
      o_client->close( ).
    ENDIF.

    IF o_client IS BOUND.

**set HTTP method
      o_client->request->set_method( if_http_request=>co_request_method_get ).

**Set header fields


      o_client->request->set_header_field( name  = 'x-rapidapi-host'
                                           value = 'airport-info.p.rapidapi.com' ).


      o_client->request->set_header_field( name  = 'x-rapidapi-key'
                                           value = 'bc72402653msh7b2eecfeed81753p17fc71jsn7b1c02627865' ).

**Set time out
*      o_client->send( timeout = if_http_client=>co_timeout_default ).
       o_client->send( EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state        = 2 ).

** read response, http Status , Payload
      o_client->receive( EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state = 2
      http_processing_failed = 3
      OTHERS = 4 ).

      DATA: lv_http_status TYPE i,
            lv_status_text TYPE string.

      o_client->response->get_status( IMPORTING code = lv_http_status
                                    reason = lv_status_text ).

      WRITE : / 'HTTP Status code :', lv_http_status,
                'Status Text : ', lv_status_text.

      IF lv_http_status = 200.
        DATA(lv_result) = o_client->response->get_data( ).
        WRITE : / 'Response :',  lv_result.

      ENDIF.
** Close http connection
      o_client->close( ).
    ENDIF.
 

 

During receive, it's throwing an  HTTP error because of some "NIECONN_REFUSED(-10)" & not due to certificate. 

I am on Zscalar VPN connection.

How to solve this? What settings should i fix? 

View Entire Topic
Azeemquadri
Contributor
0 Kudos

CREATE_BY_URL method has proxy username and password parameters. Class is CL_HTTP_CLIENT.