-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Examples of POST request with ESP8266WiFi.h #1390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can read up on HTTP. A POST request sends its payload in the body- encoding varies on what youre trying to do (file upload). Typcial case is form encoding the data. Dont have an example thought, sorry. |
Example POST to Azure void senddata(JsonObject& json) |
easy way: |
Hi, I worked on it for days to find the perfect example for the library you want to use. Let me give you an example: Serial.begin(115200); if (client.connect(host, 80)) {
} This is a proper working example for POST request using the library you mentioned and you can verify the the particular example using chrome extension POSTMAN.Let me show you the preview of the POST request i just created: POST /posts HTTP/1.1 title=foo&body=bar&userId=1 This is the post request i just created. Happy Coding :) |
any reason not to use the HTTP client ? HTTPClient http;
http.begin("http://jsonplaceholder.typicode.com/posts");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST("title=foo&body=bar&userId=1");
http.writeToStream(&Serial);
http.end(); https://github.com./esp8266/Arduino/tree/master/libraries/ESP8266HTTPClient |
Yeah HTTP client is fine I'm using something like this (not sure it's the best way but rocks) with prepared URL for emoncms
|
Should accept more than just 200 OK as a valid response code. Most common code used to indicate success with REST is 201 Created. |
@mrbubble62
|
@thorburn1 This is not about library for Arduino UNO. This is an HTTPClient library which runs on the ESP8266 itself, no external Arduino attached. |
How do I write the url for http.GET() that have a space in between letters such as example.com/default/datetime=2016-10-23 12:03:33 |
try adding a + sign between the two instead of the space |
Try using + where space would be. It might work. On Oct 23, 2016 11:56 AM, "sopan-sarkar" [email protected] wrote:
|
Hello, can someone help me with this... ` const int tmpPin = 9; String red = "clave"; String serv = "maleconjuarez.com.es"; void setup() } void resetear() } void loop() } void ConnectWifi() } void VincularTCP() if(Serial.find("ERROR")){ } void Temp() //URL Temperatura
} |
First, Use the Postman Google Chrome extension app and check wether it sends the data or not. |
Does anybody have an example of using ESP8266HTTPClient.POST with a multipart or octet stream. I'm trying to POST a JPEG. |
Does anybody have solution for one esp8266 as a client and other esp8266 as server where client send data and server accept that data and server send response after receiving data |
There is a post online claiming he achieved this over mqtt architecture.
But didn't find any source code till date.
…On Jul 6, 2017 11:34 AM, "sagar87966" ***@***.***> wrote:
Does anybody have solution for one esp8266 as a client and other esp8266
as server where client send data and server accept that data and server
send response after receiving data
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1390 (comment)>,
or mute the thread
<https://github.com./notifications/unsubscribe-auth/AS3BTolrfRrt9tu_JRgCkCwPlQ8CkEDIks5sLHjWgaJpZM4HBfkR>
.
|
This is the best I could do. I manually created the multi-part POST and sent the buffer with the WiFi Client, like some other people have suggested. https://github.com./adjavaherian/solar-server/blob/master/lib/Poster/Poster.cpp |
Hello guys, I want to post the .bin file (aka sketch) between 2 ESP-s. So first ESP will post its own sketch(firmware) to second ESP's /update url to update its firmware. |
@diffstorm I guess what you are trying to do it OTA. |
@HugoSH I know them indeed, my idea is based them. I have studied both classes you pointed. How an ESP can upload it's own firmware (.bin) to another ESP's ESP8266HttpUpdateServer page (url/update)? That was my question. Thanks. |
Hello! Anybody experienced in POSTing a file from SPIFFS? void bing() { rc = c.sendRequest("POST", &f, n); Serial.println("Finished"); I always get ERROR .3. The file os readable, n has the correct size: begin: 1 Finished |
Hi, It's possible to send a POST request with Object.addHeader("Content-Type", "application/json") in ESP8266httpclient library? I'm trying to do this but doesn't work. |
Hello guys! POST /rods/airlo/firstmodule/ HTTP/1.1 Host: iotsystem.synology.me:314 Content-Type: application/json Cache-Control: no-cache Postman-Token: (it's a long code with numbers and letters but I won't poste here for security reasons) The way I see there's only two reasons why I can't send the data: I'm not puting these data correctly in my code or he gave me wrong data. Thanks a lot!! |
And your code is...?
Em Qui, 19 de abr de 2018 22:34, chakibe <[email protected]>
escreveu:
… Hello guys!
I'm a begginer at programming with ESP8266, Arduino IDE and C++.
I've made small progress by connecting the ESP8266 to my home wifi,
however I'd like to send some data to my uncle web server through a POST
request and I'm not making any progress.
I've already tried to send the data using the WiFiClient library and the
ESP8266HTTPClient library but none of them worked. I'm starting to think
that maybe the web server data that my uncle gave me are not correct.
Here is the data he gave me:
POST /rods/airlo/firstmodule/ HTTP/1.1
Host: iotsystem.synology.me:314
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: (it's a long code with numbers and letters but I won't
poste here for security reasons)
The way I see there's only two reasons why I can't send the data: I'm not
puting these data correctly in my code or he gave me wrong data.
Can anyone help me?
Thanks a lot!!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1390 (comment)>,
or mute the thread
<https://github.com./notifications/unsubscribe-auth/AMptcf4dwg21daVftEv2Ap-hxNYFFoIiks5tqTsjgaJpZM4HBfkR>
.
|
I tried to write just like this, like the example above Serial.begin(115200); if (client.connect(host, 80)) { client.println("POST /rods/airlo/firstmodule/ HTTP/1.1"); long interval = 2000; while(!client.available()){ if( (currentMillis - previousMillis) > interval ){
} while (client.connected()) However it's always an HTTP error code |
Youre posting urlencoded, not json! |
Use a linux-system:
First edit http-server.txt:
HTTP/1.0 200 OK
Content-Length: 10
Hallo Welt
nc -l 80 < http-server.txt
And - by the way - why do you program your own http-client? There is one in the library!
Greetungs
Winfried
Am 23.04.2018 um 03:36 schrieb chakibe <[email protected]<mailto:[email protected]>>:
I tried to write just like this, like the example above
Serial.begin(115200);
while(!Serial){}
WiFiClient client;
const char* host="http://jsonplaceholder.typicode.com/";
String PostData = "title=foo&body=bar&userId=1";
if (client.connect(host, 80)) {
client.println("POST /rods/airlo/firstmodule/ HTTP/1.1");
client.println("Host: iotsystem.synology.me:314<http://iotsystem.synology.me:314>");
client.println("Cache-Control: no-cache");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
long interval = 2000;
unsigned long currentMillis = millis(), previousMillis = millis();
while(!client.available()){
if( (currentMillis - previousMillis) > interval ){
Serial.println("Timeout");
blinkLed.detach();
digitalWrite(2, LOW);
client.stop();
return;
}
currentMillis = millis();
}
while (client.connected())
{
if ( client.available() )
{
char str=client.read();
Serial.println(str);
}
}
}
However it's always an HTTP error code
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1390 (comment)>, or mute the thread<https://github.com./notifications/unsubscribe-auth/AfaTKVzRUaeafrKTPIMxX0ShhnVwqvyMks5trTAhgaJpZM4HBfkR>.
|
hi const char* ssid = ""; void setup () { Serial.begin(115200); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) {
} } void loop() { if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
} delay(30000); //Send a request every 30 seconds }` |
Hi, The PHP file on the server works for sure - when i run it via the browser, it creates the HTML file. Here is the INO file i'm using, it's not producing any error messages, and connects to the client server but it does not transfer the DATA variable.
and the PHP file:
(it didn't go so well with code sections quotes...) any advice? Tahnk you. |
Hello! First a tipp for debugging:
Second a question: Why doun't You use esp8266httpclient instead? It's not necessarry Winfried |
Hey,
I have been trawling the web looking for an example of a POST request using the ESP8266WiFi.h library. Please can you help.
Thanks
James
The text was updated successfully, but these errors were encountered: