cancel
Showing results for 
Search instead for 
Did you mean: 

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

shyam_uthaman
Participant
0 Kudos

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);

}

0 Kudos

Hi,

I am trying to create an XSJS using this process and the code below, and testing the XSJS in a browser always returns:

Error while executing query: [WebEntityResponse.setBody: expected either a string, integer, boolean, double, blob or WebResponse as an argument. If you want to add complex objects, please convert them to a string before adding them.]

I have looked a few different examples for creating this type of service and what I have done seems consistent with the examples I have found.

Is there anything obvious that I am doing wrong? Thanks! Mel

Accepted Solutions (1)

Accepted Solutions (1)

shyam_uthaman
Participant

Hi,

Fixed it.

To anyone who faces the same problem, the solution is to use the line:

request.contentType = "text/xml";

Cheers,

Shyam

Answers (0)