Skip to Content
author's profile photo Former Member
Former Member

Content-Type for POST request

Hi all again,

I am setting content-type in the header to "text/xml" yet when I do a POST sap sends as content-type

"application/x-www-form-urlencoded". Is there something else I need to set to make it post with text/xml ?

  cl_http_client=>create_by_url( EXPORTING url = url
                                           ssl_id = 'ANONYM'
                                 IMPORTING client = http_client ).
* create HTTP client object
*  cl_http_client=>create_by_destination( EXPORTING DESTINATION = 'ZTOLLREQUEST'
*                                 IMPORTING client = http_client ).
                                                                                * Set HTTP headers
  http_client->request->set_header_field( name = '~request_method'
  value = 'POST' ).
  http_client->request->set_header_field( name = 'Content-Type'
  value = 'text/xml' ).
*  http_client->request->set_header_field( name = 'Authorization'
*  value = auth_string ).
*  http_client->request->set_header_field( name = 'sap-password'
*  value = 'ymous' ).
                                                                                * Set payload
  http_client->request->set_cdata( xml_string ).
                                                                                * send and receive
  CALL METHOD http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

regards

Allan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Oct 18, 2006 at 06:18 AM

    Hi Allan,

    How did you find that SAP sends as "application/x-ww...

    here is what i use along with encoding and never had any problem

    call method http_client->request->set_header_field
      exporting
        name  = 'Content-Type'
        value = 'text/xml; charset=utf-8'.

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Raja,

      thank you again 😊

      The response I am getting from the (other companies) server is

      Invalid MediaType in ContentType, expected text/xml but got application/x-www-form-urlencoded
      

      I don't know any easy way of checking the outgoing headers to see if this is true.

      I have tried your code snipet with the charset and I still get the same result.

      Regards

      Allan

  • Posted on Oct 18, 2006 at 06:43 AM

    i havent tried this (setting content type) when using create by url . may be try just the create method and then set the remaining part of the url as headers ~request_uri parameter. something like below.

    call method cl_http_client=>create
      exporting
        host          = 'www.webservicex.net'
        service       = '80'
        scheme        = '1'
        proxy_host    =  wf_proxy
        proxy_service =  wf_port
      importing
        client        = http_client.
    
    http_client->propertytype_logon_popup = http_client->co_disabled.
    
    wf_user = user .
    wf_password = password .
    
    call method http_client->authenticate
      exporting
        proxy_authentication = 'X'
        username             = wf_user
        password             = wf_password.
    
    
    call method http_client->request->set_header_field
      exporting
        name  = '~request_method'
        value = 'POST'.
    
    call method http_client->request->set_header_field
      exporting
        name  = '~server_protocol'
        value = 'HTTP/1.1'.
    
    call method http_client->request->set_header_field
      exporting
        name  = '~request_uri'
        value = '/airport.asmx'.
    
    

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.