HTTP POST with NodeMCU module using Arduino IDE -
i have nodemcu wifi module , code in arduino ide. have have problem sending something, using post method , reading page. have php page returns 2 variables. code below:
#include <arduino.h> #include <esp8266wifi.h> #include <esp8266wifimulti.h> #include <esp8266httpclient.h> #define use_serial serial esp8266wifimulti wifimulti; httpclient http; void setup() { use_serial.begin(115200); // use_serial.setdebugoutput(true); use_serial.println(); use_serial.println(); use_serial.println(); (uint8_t t = 4; t > 0; t--) { use_serial.printf("[setup] wait %d...\n", t); use_serial.flush(); delay(1000); } wifimulti.addap("ssid", "password"); } void loop() { // wait wifi connection if ((wifimulti.run() == wl_connected)) { httpclient http; use_serial.print("[http] begin...\n"); // configure traged server , url http.begin("http://server/test.php"); // http http.addheader("content-type", "application/x-www-form-urlencoded"); http.post("id=s1&api=123456789"); http.writetostream(&serial); http.end(); use_serial.print("[http] get...\n"); // start connection , send http header int httpcode = http.get(); // httpcode negative on error if (httpcode > 0) { // http header has been send , server response header has been handled use_serial.printf("[http] get... code: %d\n", httpcode); // file found @ server if (httpcode == http_code_ok) { string payload = http.getstring(); use_serial.println(payload); } } else { use_serial.printf("[http] get... failed, error: %s\n", http.errortostring(httpcode).c_str()); } http.end(); } delay(10000); }
when run it, 411 error code. whats wrong here? how can solve it?
tested arguments in postman , ok.
Comments
Post a Comment