Skip to Content
0
Jan 20, 2016 at 05:38 PM

Cannot force content type to XML when making an XSJS call to webservice

434 Views

Hi All,

I am trying to reach a webservice which throws an error of unsupported media type.

The sent block is an XML which is what is expected, but what reaches is text/html as per the admins.

When I try to force the change of media type by $.request.contentType = "application/xml"

I get the error : WebEntityRequest.contentType : cannot modify contentType

What could be the problem? Looking forward to your replies.

Code:

var destination = $.net.http.readDestination("path","Webservice);

var client = new $.net.http.Client();

var request = new $.net.http.Request($.net.http.POST, "");

var data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'

+'<soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn = "urn:sap-com:document:sap:rfc:functions">'

+ '<soapenv:Header/>'

+ '<soapenv:Body>'

...some xml

+ '</soapenv:Body>'

+ '</soapenv:Envelope>' ;

try{

request.setBody(data);

$.request.contentType = "application/xml" ; \\ This i just added after I got the unsupported media type problem

client.request(request, destination);

var response = client.getResponse();

var resBody = response.body.asString();

$.response.contentType = "text/xml";

$.response.status = $.net.http.OK;

$.response.setBody(data);

}

catch(errObj){

$.response.setBody(errObj.message);

}