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

How to send JSON and receive binary via http post

Regular Member

How to send JSON and receive binary via http post

Hi everyone,
is there a way in thingworx to make a http post request with JSON or text content to an external service and receive a BLOB?

 

 

 

// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON({
url: "http://xyz:8080/createFile",
content: {"filename":"test"}
});

Things["MyRepository"].SaveBinary({
    path: "/",
    content: result 
});

 

 

 

The PostJSON method expects a JSON response but we would like to store the received binary in a file repository.

 

Is there a more generic way to make HTTP requests or do we have to create a extension for that.

Thanks

3 REPLIES 3
Highlighted

Re: How to send JSON and recieve binary via http post

Hi @JayT9000.

 

Without knowing more regarding your use case, it sounds like the information is being returned as JSON.  Therefore, you would need to parse it for the desired information.

 

If we're failing to understand your request, please provide details of your use case and we'll take another shot at it.

 

Regards.

 

--Sharon

Highlighted

Re: How to send JSON and recieve binary via http post

Hi Sharon,
Thanks for your reply. We have an external service which generates a binary file and we would like to store it in a file repository in thingworx. It seems that all http requests of the ContentLoaderFunctions resources expects the same output like the input.
e.g.
PostJSON -> send JSON --> expect JSON as result
PostBinary -> send BLOB --> expect BLOB as result

But in our case the service needs to receive JSON via post and sends a blob back.
Do you have any ideas?

Best regards
Jan

Highlighted

Re: How to send JSON and recieve binary via http post

Hi @JayT9000.

 

We're still not clear on your use case.  You indicated your external service is creating a binary file, but then state that the service needs to receive JSON.  What is this external service that is generating the binary file?  If you want it stored in the ThingWorx repository as JSON, you will either need to convert it before sending to ThingWorx or write a service in ThingWorx to handle the conversion.  The snippets provided in ThingWorx may require some additional coding to function as needed.

 

Regards.

 

--Sharon

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________