Różnice
Różnice między wybraną wersją a wersją aktualną.
| Poprzednia rewizja po obu stronach Poprzednia wersja Nowa wersja | Poprzednia wersja | ||
| programowanie:esp32:http [2024/10/07 15:54] – sases | programowanie:esp32:http [2024/10/09 20:12] (aktualna) – sases | ||
|---|---|---|---|
| Linia 2: | Linia 2: | ||
| \\ | \\ | ||
| - | === Import === | + | ===== Import |
| <code c> | <code c> | ||
| #include < | #include < | ||
| Linia 8: | Linia 8: | ||
| \\ | \\ | ||
| - | === HTTP GET request === | + | ===== GET request |
| <code c> | <code c> | ||
| - | String url = " | ||
| - | |||
| if(WiFi.status()== WL_CONNECTED) | if(WiFi.status()== WL_CONNECTED) | ||
| { | { | ||
| + | String url = " | ||
| + | |||
| HTTPClient httpClient; // Utworzenie instancji | HTTPClient httpClient; // Utworzenie instancji | ||
| httpClient.begin(url.c_str()); | httpClient.begin(url.c_str()); | ||
| Linia 28: | 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(); | ||
| + | } | ||
| + | </ | ||
| + | |||