HTTPClient http.POST("getting nowhere") isn't received by client

avnergid
Posts: 6
Joined: Fri Mar 27, 2020 7:36 pm

HTTPClient http.POST("getting nowhere") isn't received by client

Postby avnergid » Fri Mar 27, 2020 7:43 pm

Trying to use HTTPClient's http.POST() like in this example:

Code: Select all

  if (https.begin(*client, connectionString)) {
    https.addHeader("Content-Type", "multipart/form-data"); 
    Serial.println(https.POST("query1=12345&query2=134684&query3=1")
   
but nothing is received on the other end.
wrote a stupid PHP file to mimic the issue I'm having

Code: Select all

<?php 
if (empty($_POST)) echo "empty!";
foreach ($_POST as $key => $value) {
    echo $key;
    echo $value;
}?>
which returns code 200 and body of 'empty!' from the PHP.

here is the full code.
Is it a bug ? what am I missing here ?


Code: Select all

#include <Arduino.h>
const char* ssid =    "XX";
const char* password = "XXX";
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
void setup() {
Serial.begin(115200);
initiateNetwork();
thingsSpeakLogger();
}
void loop() {}
int thingsSpeakLogger(){
  WiFiClient *client = new WiFiClient;
  HTTPClient https;
  String connectionString = "http://192.168.1.200/postparam.php";
  
  if (https.begin(*client, connectionString)) {
    https.addHeader("Content-Type", "multipart/form-data"); 
    Serial.println(https.POST("query1=12345&query2=134684&query3=1"));  
    Serial.println(https.getString());
    delete client;
  }
}

void initiateNetwork() {
  WiFi.begin(ssid, password);  delay(1000);
  while (WiFi.status() != WL_CONNECTED)  {
    delay(300);  Serial.print(".");
  }
  Serial.println("Conneted to Wifi. IP Address: " + String(WiFi.localIP().toString().c_str())  + " MAC address: " + String(WiFi.macAddress()));

}

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: HTTPClient http.POST("getting nowhere") isn't received by client

Postby ESP_Sprite » Sat Mar 28, 2020 1:05 pm

Moved to the Arduino subforum.

Who is online

Users browsing this forum: No registered users and 107 guests