Różnice
Różnice między wybraną wersją a wersją aktualną.
| Poprzednia rewizja po obu stronach Poprzednia wersja | |||
| programowanie:esp32:http [2024/10/07 15:56] – sases | programowanie:esp32:http [2024/10/09 20:12] (aktualna) – sases | ||
|---|---|---|---|
| Linia 10: | Linia 10: | ||
| ===== GET request ===== | ===== GET request ===== | ||
| <code c> | <code c> | ||
| - | |||
| - | |||
| if(WiFi.status()== WL_CONNECTED) | if(WiFi.status()== WL_CONNECTED) | ||
| { | { | ||
| Linia 30: | Linia 28: | ||
| } | } | ||
| </ | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ===== POST request ===== | ||
| + | <code c> | ||
| + | if(WiFi.status() == WL_CONNECTED) | ||
| + | { | ||
| + | String url = api_url + "/ | ||
| + | String payload = " | ||
| + | |||
| + | HTTPClient httpClient; | ||
| + | httpClient.begin(url); | ||
| + | httpClient.addHeader(" | ||
| + | httpClient.addHeader(" | ||
| + | int httpResponseCode = httpClient.POST(payload); | ||
| + | |||
| + | if (httpResponseCode > 0) | ||
| + | { | ||
| + | if (httpResponseCode == 200) | ||
| + | { | ||
| + | String response = httpClient.getString(); | ||
| + | // Serial.println(response); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | } | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | } | ||
| + | httpClient.end(); | ||
| + | } | ||
| + | </ | ||
| + | |||