2014 Aug 14 2:11 AM
Guys,
I am trying to call a Google API directly from the ABAP code using CL_HTTP_CLIENT. While calling the URL I am getting error message 'Connection Failed', this is Google Geocoding API.
*&---------------------------------------------------------------------*
*& Report YGEOCODE
*&---------------------------------------------------------------------*
REPORT ygeocode.
*Selection-screen
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: lv_input TYPE string DEFAULT 'http://maps.googleapis.com/maps/api/geocode/xml?address=',
lv_addr TYPE string.
SELECTION-SCREEN END OF BLOCK b1.
CONSTANTS: lv_n TYPE c VALUE '&',
lv_sensor TYPE char7 VALUE 'sensor=',
lv_false TYPE char5 VALUE 'false'.
DATA : lv_value TYPE string.
DATA : http_client TYPE REF TO if_http_client .
DATA : lv_url TYPE string.
DATA : return TYPE string.
DATA : lv_err_string TYPE string ,
lv_ret_code TYPE sy-subrc .
* Build Url
CONCATENATE lv_input lv_addr lv_n lv_sensor lv_false
into lv_url.
TRANSLATE lv_url TO LOWER CASE.
* Create Client
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = http_client.
* Send
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
* Receive
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
IF sy-subrc NE 0.
http_client->response->get_status(
IMPORTING
code = lv_ret_code
reason = lv_err_string
).
MESSAGE lv_err_string TYPE 'I'.
ENDIF.
* Now we have the response , parse , display
* do what you like
return = http_client->response->get_cdata( ).
-------------------------------------------------------------------------------------------
What could be the issue ?
Dj,
2014 Aug 14 6:53 AM
Dear Mike,
Please go through the below link.
https://scn.sap.com/thread/1435555
Thanks & Best Regards,
Dinu