hi guys:
I am building a node js server . I've not found any example that can help me to send POST request from my arduino mkr wifi 1010 to the server yet . Does anyone have example to help me with it?
i think that i should use httpclient library but how to do that .
I suggest to use the ArduinoHttpClient library (available in the library manager). It comes with a POST example.
hi pylon , thank you verry much i used this library and everything works fine thank you verry much
the get request works fine i receive data from my node js server ,
but in the post request i dont receive data the body of the request is empty ,
i should send json data and i test the post request in the postman it works fine ! how can i send json format ??
this is the code for the post request :
#include <ArduinoHttpClient.h>
#include <WiFiNINA.h>
#include <Arduino_JSON.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
/////// Wifi Settings ///////
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
char serverAddress[] = "192.168.1.12"; // server address
int port = 4000;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
void setup() {
Serial.begin(9600);
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
}
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
Serial.println("making post request");
client.post("/Etiquette/listEtiquette");
// read the status code and body of the response
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
Serial.println("Wait five seconds");
delay(5000);
}
You didn't have a look at one of the POST examples, did you?
You have two ways to send a post request. One is shown in SimplePost, the other in PostWithHeaders.
And always use code tags if you post code. Have a look at your post to see what happens if you don't.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.