How to send data from ESP8266 to PHP script on website?

Please look at the examples and the documentation of the HTTPClient library.

You have to call http.GET after http.begin.

Code:

---



```
void SendData(int sensor, float temp, float humid)
{
HTTPClient http;
String uri = "http://www.mydomain.com/php/tempreport.php";
String data = Stringcolor=#000000[/color] + sensor + "&temp=" + temp + "&humid=" + humid;
bool httpResult = http.begin(uri + data);
if color=#000000[/color] {
SerialDebug.println("Invalid HTTP request:");
SerialDebug.println(uri + data);
}
int httpCode = http.GETcolor=#000000[/color];
if (httpCode > 0) { // Request has been made
SerialDebug.printf("HTTP status: %d\n", httpCode);
String payload = http.getStringcolor=#000000[/color];
SerialDebug.printlncolor=#000000[/color];
} else { // Request could not be made
SerialDebug.printf("HTTP request failed. Error: %s\r\n", http.errorToStringcolor=#000000[/color].c_strcolor=#000000[/color]);
}
http.endcolor=#000000[/color];
}
```

BosseB:
I see no point in separating the destination and data if they could be sent in one single transaction as a composite URL.
That would be the same as I do in FireFox...

The HTTP specification requires you to use POST if a request has side effects (e.g. inserting temperature and humidity data into a database). GET requests should only retrieve information, without altering the internal state of the server.
You can of course choose not to follow the standard, but that will cause problems with caching and resubmission of the data.