cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Error executing GetJSON in service - Invalid Content Type: text/html

DV_9683959
4-Participant

Error executing GetJSON in service - Invalid Content Type: text/html

Hello guys,

 

I have a service in ThingWorx 9 where I am trying to use the GetJSON from ContentLoaderFunctions to get the data for a ThingWorx project but I get the following error: " Message :: Invalid Content Type: text/html". I checked the logs and there are no other errors.

 

I tried to do this request from Postman and it works fine. Also tried a PostJSON and it works fine, so the appKey it's ok. I also tested the javascript from below with ThingWorx 8.5 and it works without any issues...but for ThongWorx 9 it simply does not work.

 

You can find below the javascript code from my service:

 

var params = {

  headers: {
     "appKey": "6b2c8c8b-423e-5a56-c321-5e378ff55662",
     "Content-type": "application/json"
      } /* JSON */,
   url: "http://localhost/Thingworx/Projects/daniel_test_99" /* STRING */
};

 

var result = Resources["ContentLoaderFunctions"].GetJSON(params);

 

If it's important "daniel_test_99" it's a local Project with no dependencies.

ThingWorx version: 9.0

 

Do you have any idea why it's not working?

Thanks!

8 REPLIES 8
ptc-914827
5-Regular Member
(To:DV_9683959)

I have the same problem!

What's the output type of GetJson service and your own script?

DV_9683959
4-Participant
(To:zyuan1)

Output type is JSON.

ptc-914827
5-Regular Member
(To:DV_9683959)

The workaround I used is to use GetText() instead, but then you need to parse the result to json.

Since you've tested through Postman and TWX 8.5, then this script should be okay;

You're not getting 401 error, so the server's external connection is correct;

I asked what's the output type of your script to check if you forget to change the output from Nothing to Json, because it sometimes happen to me;

 

After all these, there might be some difference or even bug in the TWX 9 , you may create a case for it and let TS contact R&D.

arozbaum
5-Regular Member
(To:DV_9683959)

Hi,

 

Add the Accept header in your request,

 

var params = {

  headers: {

     ...
     "Accept": "application/json"

      } /* JSON */,
};

 

This will tell the server to respond with a JSON.

 

In the response headers, content-type tells you what the server actually sent back.

 

if you added the Accept header asking for a JSON but got text/html, notify the owner of the server that if the server cannot respond in accordance to the Accept cookie it should return a 406.

most likely it will be fixed and the server will return a JSON.

 

Thanks,

Arkady. 

 

 

Hope this works.

slangley
23-Emerald II
(To:DV_9683959)

Hi @DV_9683959.

 

If one of the previous responses allowed you to find a solution, please mark the appropriate one as the Accepted solution for the benefit of others with the same issue.

 

Regards.

 

--Sharon

Announcements


Top Tags