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

Content-Type for POST request

Former Member
0 Likes
8,314

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

1 ACCEPTED SOLUTION
Read only

athavanraja
Active Contributor
0 Likes
3,152

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

5 REPLIES 5
Read only

athavanraja
Active Contributor
0 Likes
3,153

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

Read only

0 Likes
3,152

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

Read only

athavanraja
Active Contributor
0 Likes
3,152

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

Read only

0 Likes
3,152

Thanks Raja,

It didn't work. As best as I can figure it it seems that http_client->request->set_header_field only allows certain fields to be set or they are overwritten at send time.

For example ~request_uri and Content-Type seemed to be ignored while ~request_method does seem to work.

It would be nice if there was some documentation for this

Thanks & regards

Allan

Read only

0 Likes
3,152

hi again,

I should mention the system is Netweaver 04, in case that makes a difference.

Allan