cancel
Showing results for 
Search instead for 
Did you mean: 

CL_HTTP_CLIENT, HTTP POST of XML as a form field, encoding

Former Member

I am working on a couple of interfaces between a SAPsystem (NetWeaver 2004s, ABAP stack) and another system.

On the SAP side we are using the built-in HTTP-client (CL_HTTP_CLIENT).

For the interface from SAP to the other system, the other system expects an XML as the value of a form field in an HTTP POST request.

In fact, it was described as doing the equivalent to this HTML-fragment in a web-browser:

<form action="http://over.there.com/interface/import.php" method="post">

<p>Please enter your xml data:

<textarea name="data" cols="50" rows="10"></textarea>

<input type="submit" value="submit">

</p>

</form>

I assume I will have to do a SET_METHOD in order to get the POST method (as opposed to GET) and a SET_FORM_FIELD (for field "data").

According to the reference I found at W3C ( http://www.w3.org/TR/html4/interact/forms.html ), the default encoding method for a POST is "application/x-www-form-urlencoded". Does this mean I have to do this encoding myself?

Could I opt for another encoding - "text/xml" for example? If so, how? With a SET_HEADER_FIELD?

Accepted Solutions (0)

Answers (1)

Answers (1)

athavanraja
Active Contributor

here is the sample code to do the stuffs you requested


DATA: http_client TYPE REF TO if_http_client .
call method cl_http_client=>create
  exporting
    host          = 'www.xxxx.com'
    service       = '80'
    scheme        = '1'
  importing
    client        = http_client.


call method http_client->request->set_header_field
  exporting
    name  = '~request_method'
    value = 'POST'.

http_client->request->if_http_entity~set_form_field(
    name   = 'data'
    value  = 'the xml to be passed to this form field'
       ).

CALL METHOD http_client->request->set_header_field
  EXPORTING
    name  = 'Content-Type'
    value = 'text/xml; charset=utf-8'.

Former Member
0 Kudos

Thank you.

This is how we set the context-type:


    call method client->request->if_http_entity~set_content_type
        exporting
          content_type = p_contyp.

where p_contyp contained 'text/xml'.

This is how we set the form-field data:


call method client->request->if_http_entity~set_form_field
        exporting
          name  = p_formfd
          value = xmlstring.

where p_formfd contained 'data' - the name that was specified.

This is how we make the request a POST:


call method client->request->set_method
      exporting
        method = 'POST'.