cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using HTTP_CLIENT-->receive, NIECONN_REFUSED error

Amey-Mogare
Contributor
5,255

Hi,

I am facing Http_Communication_Failure in using IF_HTTP_CLIENT->receive method.

SICM logs gives following error:-

NIECONN_REFUSED

Also when I tested same url with FM HTTP_GET, it gives Connect error as "NiHostToAddr <hostname> error: NIEHOST_UNKNOWN

I really surprised to see that this was working fine few weeks back.

Now suddenly it has stopped working.

Please help.

Thanks and regards,

Amey

Accepted Solutions (0)

Answers (1)

Answers (1)

Amey-Mogare
Contributor
0 Likes

Resolved myself.


"STEP-1 : CREATE HTTP CLIENT
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
    EXPORTING
      URL                = WL_URL
    IMPORTING
      CLIENT             = W_HTTP_CLIENT
    EXCEPTIONS
      ARGUMENT_NOT_FOUND = 1
      PLUGIN_NOT_ACTIVE  = 2
      INTERNAL_ERROR     = 3
      OTHERS             = 4
      .

  DATA: EMPTYBUFFER TYPE XSTRING.

      EMPTYBUFFER = ''.
  CALL METHOD W_HTTP_CLIENT->REQUEST->SET_DATA
        EXPORTING DATA = EMPTYBUFFER.

"STEP-2 :  AUTHENTICATE HTTP CLIENT
CALL METHOD W_HTTP_CLIENT->AUTHENTICATE
  EXPORTING
    USERNAME             = 'user'
    PASSWORD             = 'password'
    "LANGUAGE             = SY-LANGU
    .

CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
     EXPORTING NAME  = '~request_method'
               VALUE = 'GET'
                .

 CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'Content-Type'
                VALUE = 'text/xml; charset=utf-8'.

 CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'Accept'
                VALUE = 'text/xml, text/html'.

 CONCATENATE WL_URL '#' INTO SOAP_ACTION.
 CALL METHOD W_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD
      EXPORTING NAME  = 'SOAPAction'
                VALUE = SOAP_ACTION.

"STEP-3 :  SEND HTTP REQUEST
  CALL METHOD W_HTTP_CLIENT->SEND
    EXCEPTIONS
      HTTP_COMMUNICATION_FAILURE = 1
      HTTP_INVALID_STATE         = 2.

*-----------------------------------------------------------------

"STEP-4 :  GET HTTP RESPONSE
    CALL METHOD W_HTTP_CLIENT->RECEIVE
      EXCEPTIONS
        HTTP_COMMUNICATION_FAILURE = 1
        HTTP_INVALID_STATE         = 2
        HTTP_PROCESSING_FAILED     = 3.

"STEP-5 : Read HTTP RETURN CODE
CALL METHOD W_HTTP_CLIENT->RESPONSE->GET_STATUS
    IMPORTING
      CODE = HTTP_STATUS_CODE
      REASON = STATUS_TEXT
      .
  WRITE: / 'HTTP_STATUS_CODE = ',
          HTTP_STATUS_CODE,
         / 'STATUS_TEXT = ',
         STATUS_TEXT
         .

"STEP-6 :  READ RESPONSE DATA
 CALL METHOD W_HTTP_CLIENT->RESPONSE->GET_CDATA
        RECEIVING DATA = W_RESULT .

SudheerHarman
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello,

Could you please let me know how you solved this issue?

Regrads,

Sudheer

Amey-Mogare
Contributor
0 Likes

Hi Sudheer,

I could resolve the issue by the exact code I typed in my reply above.

I was not setting some HTTP attributes previously (content-type n etc).

Once I set those in http-client's object, it started working.

Try using same code that I put up.

Hope it helps.

Thanks,

Amey