I tested this simple example of node.js code:
var http = require("http");
var options = {
host: "localhost",
port: "8080",
path: "/Thingworx/Things/ExampleThing/Properties/name",
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "text/xml",
"appKey": "app_key"
}
};
http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
}).end();
That returned expected response in the body just like in Postman:
BODY: <?xml version="1.0" encoding="UTF-8" standalone="no"?><InfoTable><DataShape><FieldDefinitions><FieldDefinition aspect.isBuiltIn="true" aspect.isPersistent="false" aspect.isReadOnly="true" baseType="STRING" category="Metadata" description="Thing name" isLocalOnly="true" name="name" ordinal="0"/></FieldDefinitions></DataShape><Rows><Row><name><![CDATA[LocalThing]]></name></Row></Rows></InfoTable>
Or set "Accept" to "application/json" to get output in JSON format:
BODY: {"dataShape":{"fieldDefinitions":{"name":{"name":"name","description":"Thing name","baseType":"STRING","ordinal":0,"aspects":{"isReadOnly":true,"isPersistent":false,"isBuiltIn":true}}}},"rows":[{"name":"LocalThing"}]}
But when I set "Accept to "text/html" I get HTML body:
BODY: <HTML><HEAD><TITLE>Property Value For LocalThing : name</TITLE><LINK rel='Stylesheet' href='/Thingworx/css/thingworxapi.css' type='text/css'></LINK><META http-equiv='Content-Type' content='text/html'></META><META http-equiv='cache-control' content='no-cache, no-store'></META><META http-equiv='expires' content='-1'></META><META http-equiv='pragma' content='no-cache, no-store'></META></HEAD><BODY><IMG src="/Thingworx/images/ThingworxLogo.png"/><BR/><H1>Property Value For LocalThing : name</H1><TABLE><TR><TH>name</TH></TR><TR><TD>LocalThing</TD></TR></TABLE></BODY></HTML>
Try this and let me know if you get the expected response.