Skip to Content
0
Former Member
Feb 19, 2009 at 06:33 PM

ICM_HTTP_CONNECTION_FAILED error on http receive method

1005 Views

Hi,

I am trying to read a XML via http. I have developed a code referencing this blog:

/people/rashid.javed/blog/2007/03/11/cricket-world-cup-http-client-and-simple-transformations

When http receive method is executed it gives me an error.

On executiong of: CALL METHOD client->receive it gives error:

code: 400 message: ICM_HTTP_CONNECTION_FAILED

I treid changing host and buf in code below both to http://www.google.com to rule out the possibility of bad url. Also tried setting time out to 500 in send method. Still no luck.

ICM trace shows following:

Thr 4864] *** WARNING => Connection request from (16/6462/1) to host: http://www.google.com/, service: 80 failed (NIEHOST_UNKNO

How do I solve this error, please give me some tips.

I was looking forum for this issue but was not able to find a solution.

Here is complete code:

DATA: client TYPE REF TO if_http_client.
DATA: host TYPE string.
* DATA: proxyh TYPE string VALUE 'IfYouHave.Proxy.com',
*      proxyp TYPE string VALUE '8080'.

DATA: buff TYPE string,
      respd TYPE string.
DATA: subrc TYPE sysubrc.


CALL METHOD cl_http_client=>create
  EXPORTING
    host               = 'http://www.google.com/ig/api'
*    SERVICE            =
*    proxy_host         = proxyh
*    proxy_service      = proxyp
*    SCHEME             = SCHEMETYPE_HTTP
*    SSL_ID             =
*    SAP_USERNAME       =
*    SAP_CLIENT         =
  IMPORTING
    client             = client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4
        .

IF sy-subrc <> 0.
  WRITE:/ ' cl_http_client=>create, subrc = ', sy-subrc.
  EXIT.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.

  buff = 'GET'.
  CALL METHOD client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = buff.

  buff = 'http://www.google.com/ig/api?weather=21218&hl=en'.

  cl_http_utility=>set_request_uri( request = client->request
                                    uri     = buff ).
  subrc = cl_http_utility=>get_last_error( ).
  IF subrc <> 0.
    WRITE: / 'Wrong URI format'.
    EXIT.
  ENDIF.

ENDIF.

CALL METHOD client->send
*  EXPORTING
*    TIMEOUT                    = CO_TIMEOUT_DEFAULT
  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 client->get_last_error
    IMPORTING
      code    = subrc
      MESSAGE = buff.
  WRITE: / 'communication_error( send )',
         / 'code: ', subrc, 'message: ', buff.
  EXIT.
ENDIF.


CALL METHOD client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    OTHERS                     = 4.
IF sy-subrc <> 0.
  CALL METHOD client->get_last_error
    IMPORTING
      code    = subrc
      MESSAGE = buff.
  FORMAT COLOR COL_BACKGROUND.
  WRITE: / 'communication_error( receive )',
         / 'code: ', subrc, 'message: ', buff.
  WRITE: / 'communication_error'.
  EXIT.
ENDIF.


respd = client->response->get_cdata(  ).

WRITE:/ respd.

Thanks in advance,

CD

Edited by: CD on Feb 19, 2009 1:46 PM