0
0
Arduinoprogramming~20 mins

HTTP requests from Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arduino HTTP Requests Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Arduino HTTP GET request code?

Consider this Arduino sketch snippet that makes an HTTP GET request to a server and prints the response code. What will be printed to the Serial Monitor?

Arduino
WiFiClient client;
HTTPClient http;

void setup() {
  Serial.begin(115200);
  WiFi.begin("SSID", "PASSWORD");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  http.begin(client, "http://example.com");
  int httpCode = http.GET();
  Serial.println(httpCode);
  http.end();
}

void loop() {}
A200
B0
C-1
D404
Attempts:
2 left
💡 Hint

HTTP status code 200 means success. The code variable holds the HTTP response code.

🧠 Conceptual
intermediate
1:30remaining
Which Arduino library is used for making HTTP requests?

You want to send HTTP GET and POST requests from your Arduino sketch. Which library provides the HTTPClient class to do this?

AEthernet.h
BWiFi.h
CSPI.h
DHTTPClient.h
Attempts:
2 left
💡 Hint

Look for the library that has 'HTTP' in its name and provides HTTP methods.

🔧 Debug
advanced
2:30remaining
Why does this Arduino HTTP POST code fail to send data?

Examine the code below. It tries to send JSON data via HTTP POST but the server never receives it. What is the main reason for failure?

Arduino
WiFiClient client;
HTTPClient http;

void setup() {
  Serial.begin(115200);
  WiFi.begin("SSID", "PASSWORD");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  http.begin(client, "http://example.com/api");
  http.addHeader("Content-Type", "application/json");
  int httpCode = http.POST("{\"temp\": 25}");
  Serial.println(httpCode);
  http.end();
}

void loop() {}
AThe HTTPClient.begin() is called with WiFiClient instead of WiFiClientSecure
BThe WiFi connection is not established before the POST call
CThe Content-Type header is missing
DThe JSON string is not properly escaped
Attempts:
2 left
💡 Hint

Check the WiFi connection status before making HTTP requests.

📝 Syntax
advanced
1:30remaining
Which option fixes the syntax error in this Arduino HTTP GET snippet?

Find the option that corrects the syntax error in this code snippet:

http.begin(client, "http://example.com")
int code = http.GET()
Serial.println(code)
AChange http.GET() to http.get()
BRemove parentheses from http.GET
CAdd semicolons at the end of each line
DReplace double quotes with single quotes
Attempts:
2 left
💡 Hint

Arduino C++ requires statement terminators.

🚀 Application
expert
3:00remaining
How many bytes are sent in this Arduino HTTP POST request?

Given this Arduino code sending a JSON payload via HTTP POST, how many bytes are sent in the request body?

String payload = "{\"sensor\":\"temp\",\"value\":23}";
http.begin(client, "http://example.com/data");
http.addHeader("Content-Type", "application/json");
int code = http.POST(payload);
http.end();
A28 bytes
B26 bytes
C30 bytes
D24 bytes
Attempts:
2 left
💡 Hint

Count all characters including quotes and braces in the JSON string.