user59241: Nodemcu device is returning HTTP response -1 for a POST request on django rest api.
I tried the below http request to Postman, and it works perfectly fine.
http://localhost:8000/api/datalogs/?plant=http://localhost:8000/api/plants/1/&light=23&temperature=24&humidity=75&soil=Dry&moisture=787&remarks=/
This is my arduino post request:
if(WiFi.status() == WL_CONNECTED) {
    HTTPClient http;

    http.begin(host_url);

    http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
    httpCode = http.POST(postData);

    payload = http.getString();
    http.end();
}

The expected result is 200, but I get -1. Can someone please explain?

user59241: So, I found the solution. It was a very simple mistake. The NodeMCU IP is not the same as the Computer IP that the server was running on.
I changed the localhost string with the IP of my pc, and it worked perfectly fine.

59241: <p><strong>Nodemcu</strong> device is returning <strong>HTTP response -1</strong> for a <strong>POST</strong> request on django rest api.</p>

<p>I tried the below http request to <strong>Postman</strong>, and it works perfectly fine.</p>

<p><a href="http://localhost:8000/api/datalogs/?plant=http://localhost:8000/api/plants/1/&amp;light=23&amp;temperature=24&amp;humidity=75&amp;soil=Dry&amp;moisture=787&amp;remarks=/" rel="nofollow noreferrer">http://localhost:8000/api/datalogs/?plant=http://localhost:8000/api/plants/1/&amp;light=23&amp;temperature=24&amp;humidity=75&amp;soil=Dry&amp;moisture=787&amp;remarks=/</a></p>

<p>This is my arduino post request:</p>

<pre><code>if(WiFi.status() == WL_CONNECTED) {
    HTTPClient http;

    http.begin(host_url);

    http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
    httpCode = http.POST(postData);

    payload = http.getString();
    http.end();
}
</code></pre>

<p>The expected result is <strong>200</strong>, but I get <strong>-1</strong>. Can someone please explain?</p>
 59241: <p>So, I found the solution. It was a very simple mistake. The <strong>NodeMCU IP</strong> is not the same as the <strong>Computer IP</strong> that the server was running on.</p>
<p>I changed the <strong>localhost</strong> string with the IP of my pc, and it worked perfectly fine.</p>
