Solved
Rest API returning HTML type response
Hi,
I have followed https://community.ptc.com/t5/ThingWorx-Developers/rest-api-returns-an-html-page-How-to-access-the-data/m-p/501682
But still it seems there is some problem.
I am using this piece of code from a node application, to get a property value using REST.
var data = JSON.stringify(false);
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "http://localhost:8080/Thingworx/Things/ThingName_Example/Properties/uploadPath");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "text/xml");
xhr.setRequestHeader("appKey", "PPPP9f16-XXXX-XXXX-XXXX-1b719e2UUUUU");
xhr.send(data);
and the result i get is :-
<HTML><HEAD><TITLE>Property Value For CMU_TH_DOCUMENT_REPO : uploadPath</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 CMU_TH_DOCUMENT_REPO : uploadPath</H1><TABLE><TR><TH>uploadPath</TH></TR><TR><TD>I am upload path</TD></TR></TABLE></BODY></HTML>
I think I have used correct header type, as suggested in one of the post, But I still get HTML type of response.
Is there anything I am missing?

