Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

http connection error using cl_http_client

Former Member
0 Likes
6,558

Hello,

i am  learning how to set up a connection from ABAP to an external web-server using cl_http_client, beginnig right from scratch.

For testing purposes I therefore have established an IIS7 (Windows7 internet information Service) on my localhost with an IP and

Port. I have created a XML-File in abap and now want to use the http-put method to create a file on the root of the localhost-server.

Below you can see my code.  After the create and the send-methode, sy-subrc is always 0 (Zero).  Even if I replace the '10.0.0.36'  IP in

the create method with some rubbish caracters , the sy-subrc is 0 after the send-method.  After the receive-method the subrc is suddently 1

( =  http_communication_failure ).

Maybe you can halp me and tell me why the sent-method returns subrc = 0 and maybee you can also tell me how to fix my connection problem.

Help is very much appreciated


DATA: gv_xml  TYPE string,

      gs_mara TYPE t_mara,
      gt_mara TYPE STANDARD TABLE OF t_mara.


DATA: go_client TYPE REF TO if_http_client.

* [....] Fill ITAB etc.[....]



* ABAP to XML

CALL TRANSFORMATION zmara01_xslt
  SOURCE root = gt_mara
  RESULT XML   gv_xml.


CALL METHOD cl_http_client=>create
  EXPORTING
    host               = '10.0.0.36'  "IP von C:\inetpub\wwwroot
    service            = '80'         "Standardport für http
  IMPORTING
    client             = go_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4.


* set header fields
CALL METHOD go_client->request->set_header_field
  EXPORTING
    name  = '~request_method'
    value = 'PUT'.


CALL METHOD go_client->request->set_header_field
   EXPORTING
      name  = 'Content-Type'
      value = 'xml'.



* set body

*CALL METHOD go_client->request->if_http_entity~set_cdata

     EXPORTING
      data   = gv_xml
*     offset = 0
**    length = -1

  
CALL METHOD go_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.
  WRITE: 'Send failed, subrc = ', sy-subrc.
  EXIT.
ENDIF.



CALL METHOD go_client->receive
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    others                     = 4

        .

IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.












1 REPLY 1
Read only

Former Member
0 Likes
2,794

hello,

Check these links

http://scn.sap.com/thread/1359708

http://scn.sap.com/thread/226002

best regards,

swanand