10-13-2020 10:23 AM
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.
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
Solved! Go to Solution.
10-13-2020 01:36 PM
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.
10-13-2020 02:43 PM
Thank you!