Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a http POST request using Arduino

Tags:

I am trying to post information to an API on a web project that I have created and hosted. I am not sure what the exact format is for the HTTP POST request. Every time I try I get HTTP 400 errors with the message that there is "an invalid verb".

Sample Code:

byte server[] = {"our IP"} .. ..  client(server, 80) .. .. client.println("POST /Api/AddParking/3"); 

It connects to the IP address supplied without any problems, but all I get back in the above mentioned HTTP error code 400. I am not sure if I was supposed to include a HTTP version after my POST or and Content-Length or any other information.

like image 997
Austen Bryan Avatar asked Sep 09 '10 14:09

Austen Bryan


People also ask

Can Arduino make HTTP request?

Arduino can play a role as a web client to make HTTP to a web server. Web Server can be a website, Web API or REST API, Web service ...

Can Arduino make API calls?

These are the only components needed to setup your Arduino Uno for making REST API calls. Yes! you do not need any voltage regulators, any kind of resistors, capacitors or serial to usb converters. First thing first, you need to know pin-out of your ESP8266 module.

Does ESP8266 support HTTP?

With this example, your ESP8266 can make HTTP POST requests using three different types of body requests: URL encoded, JSON object or plain text.

Can ESP32 send data to server?

So, it can connect to the ESP32 server wireless network. The client can make HTTP GET requests to the server to request sensor data or any other information. It just needs to use the IP address of the server to make a request on a certain route: /temperature, /humidity or /pressure.


1 Answers

The original question is already answered, but just for reference for people passing by via Google; here is a more complete example how to post data to a webserver with an Arduino:

IPAddress server(10,0,0,138); String PostData = "someDataToPost";  if (client.connect(server, 80)) {   client.println("POST /Api/AddParking/3 HTTP/1.1");   client.println("Host: 10.0.0.138");   client.println("User-Agent: Arduino/1.0");   client.println("Connection: close");   client.print("Content-Length: ");   client.println(PostData.length());   client.println();   client.println(PostData); } 
like image 170
stif Avatar answered Oct 05 '22 14:10

stif