LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Flatten to JSON and HTTP POST

Solved!
Go to solution

Hi

 

I'm a new LabView user. I'm trying to make a simple HTTP POST to a REST API that I've developed. Based on the few examples I've been able to find, I'm using a cluster and Flatten to JSON to create the POST body.

 

apilogind.png

 

My REST API is expecting: { "username": "foo", "password": "bar" }

 

But instead, it's getting: {"{\"username\":\"foo\",\"password\":\"bar\"}": ""}

 

In other words, it's taking my desired JSON object and making it the key of an object whose value is "".

 

What am I missing here?

 

Thanks

 

 

0 Kudos
Message 1 of 3
(3,857 Views)
Solution
Accepted by topic author markroy

Hi markroy,

 

By default the POST VI will include a HTTP Header with Content-Type: application/x-www-form-urlencoded in the POST request. My guess is that the server is seeing the Content-Type in the request and treating the request different than expected. You can use the Add Header VI to include the header needed to represent the JSON value by setting the header input to "Content-Type" and the header value input to "application/json".

 

An example on the LabVIEW POST, PUT HTTP method thread shows adding a header to a POST request. Note that the OpenHandle VI and Close Handle VI are needed when configuring the headers on a request.

 


Milan
Message 2 of 3
(3,817 Views)

Thank you!

0 Kudos
Message 3 of 3
(3,803 Views)