Error 503 in response from HTTP POST

Hi, I am at a loss as to why I am unable to POST successfully to my Dream Factory instance. I am able to send a curl from command-line successfully and receive the correct response, but when I format the data as a regular HTTP POST request and try to POST from my microcontroller C code, I get a 503 error. It looks like the error is from the ClusterService.php file. Any thoughts?

Here’s my successful curl (with authorization information redacted):

curl -X POST "https://<redacted>.dreamfactory.com/api/v2/testdb/_table/Measurements" -H "Content-Type: application/json" -H "accept: application/json"  -H "X-DreamFactory-API-Key: <redacted>" -d "{\"resource\":[{\"userID\":1,\"weight\":1,\"timestamp\":\"2018-02-17 21:05:13.5096722\",\"productID\":2,\"created_date\":\"2018-02-07 21:05:13.5096722\",\"last_updated_date\":\"2018-02-07 21:05:13.5096722\"}]}"

Curl successful response:

{"resource":[{"measurementID":21}]}

And here’s my unsuccessful HTTP POST request as used in my esp32 microcontroller code:

POST https://<redacted>.dreamfactory.com/api/v2/testdb/_table/Measurements HTTP/1.0
Accept: application/json
Connection: keep-alive
Content-Type: application/json
X-DreamFactory-API-Key: <redacted>
{"resource":[{"userID":1,"weight":32,"timestamp":"2018-01-02 00:00:00.00","productID":2,"created_date":"2018-01-01 00:00:00.00","last_updated_date":"2018-01-01 00:00:00.00"}]}

MCU error response:

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=UTF-8
Connection: close
Cache-Control: no-cache, private
Date: Wed, 28 Feb 2018 18:28:55 GMT
x-dreamfactory-routed: true

{"error":{"code":503,"message":"Error interrogating console: Corrupt response during status query for \"\"."}}

I did a google search for “Error interrogating console” and I was directed to this GitHub repository. Any guidance would be very much appreciated!

So I fixed my code and am now able to send the following request:

POST https://<redacted>.dreamfactory.com/api/v2/testdb/_table/Measurements HTTP/1.0
User-Agent: esp-idf/1.0 esp32
Connection: close
Host: <redacted>.oraclecloud2.dreamfactory.com
Authorization: <redacted>
Content-Type: application/json
X-DreamFactory-API-Key: <redacted>

{"resource":[{"userID":1,"weight":32,"timestamp":"2018-01-02 00:00:00.00","productID":2,"created_date":"2018-01-01 00:00:00.00","last_updated_date":"2018-01-01 00:00:00.00"}]}

But I’m getting the following error response:

HTTP/1.1 400 Bad Request
Server: nginx
Content-Type: application/json
Connection: close
Cache-Control: private, must-revalidate
Date: Sun, 04 Mar 2018 23:41:33 GMT
pragma: no-cache
expires: -1

{"error":{"code":400,"context":null,"message":"No record(s) detected in request. Please make sure record(s) are wrapped in a 'resource' tag. Example: {&quot;resource&quot;:[{&quot;record&quot;:1},{&quot;record&quot;:2}]}","status_code":400}}

My JSON is correct and is wrapped in a resource tag… Any thoughts?

Solved

I found out that the “Content-Length: x” header HAS to be present in any HTTP POST requests, and the value has to be correct as well. Weird HTTP thing I guess!