on 11-18-2015 11:39 AM
Hi All,
My XSJS fails to get data from an external server due to the line 08 below.
My input is an XML and the output returned is also XML and not JSON.
I just can't seem to find the corresponding XML counterpart for JSON.stringify. Let me know please if you are aware of the answer.
req.contentType = "text/xml";
req.setBody(data);
client.request(req, dest);
var response = client.getResponse();
var resBody = response.body.asString();
$.response.setBody(JSON.stringify({ //This might be the problem
"body" : resBody;
Thanks,
Shyam
Any thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In the code before the statements I have written -
var dest = $.net.http.readDestination("Path","AddrService");
var client = new $.net.http.Client();
var req = new $.net.http.Request($.net.http.GET, "service/1services/addr");
var data = '<?xml version="1.0" encoding = "UTF-8"?>'
+<inputs...>
that is why I was using the above variable req for req.contentType which may be wrong due to my inexperience with javascript.
Anyways, I modified the code in try{} block as you suggested to
response.contentType = "text/xml";
req.setBody(data);
client.request(req, dest);
var resBody = response.body.asString();
$.response.status = $.net.http.OK;
$.response.setBody(resBody);
which threw an error that "response is not defined"
Now I added another line as line 01 below to define response ( I hope that is correct)
var response = client.getResponse();
response.contentType = "text/xml";
req.setBody(data);
client.request(req, dest);
var resBody = response.body.asString();
$.response.status = $.net.http.OK;
$.response.setBody(resBody);
The current error says
Does this have something to do with the order of this code?
Thanks,
Shyam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You don't need to stringify XML. You have already got it as string
var resBody = response.body.asString();
- $.response.status = $.net.http.OK;
- $.response.contentType = "text/html";
- $.response.setBody(resBody );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for the reply but I still face the same issue.
I modified the code to
req.contentType = "text/html";
req.setBody(data);
client.request(req, dest);
var response = client.getResponse();
var resBody = response.body.asString();
$.response.status = $.net.http.OK;
$.response.setBody(resBody);
Also, the content type should be text/xml and not text/html ..right?
Let me know please.
Thanks,
Shyam
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.