0
0
Arduinoprogramming~10 mins

HTTP requests from Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to include the library needed for HTTP requests.

Arduino
#include <[1]>

void setup() {
  Serial.begin(9600);
}
Drag options to blanks, or click blank then click option'
AWire.h
BWiFi.h
CSPI.h
DHTTPClient.h
Attempts:
3 left
💡 Hint
Common Mistakes
Including WiFi.h instead of HTTPClient.h
Forgetting to include any HTTP-related library
2fill in blank
medium

Complete the code to start an HTTP GET request to the URL.

Arduino
HTTPClient http;
http.begin("[1]");
int httpCode = http.GET();
Drag options to blanks, or click blank then click option'
ASerial.begin(9600)
Bhttp://example.com
Cdelay(1000)
DWiFi.begin()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a function call instead of a URL string
Forgetting to put the URL in quotes
3fill in blank
hard

Fix the error in reading the HTTP response payload.

Arduino
if (httpCode > 0) {
  String payload = http.[1]();
  Serial.println(payload);
}
Drag options to blanks, or click blank then click option'
AgetResponse
BreadPayload
CgetString
DreadString
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like getResponse()
Using readString() which is not part of HTTPClient
4fill in blank
hard

Fill both blanks to properly close the HTTP connection and free resources.

Arduino
http.[1]();
http.[2]();
Drag options to blanks, or click blank then click option'
Aend
Bclose
Cdisconnect
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'close' or 'stop' which are not functions of HTTPClient
Not calling end() to free resources
5fill in blank
hard

Fill all three blanks to create a dictionary of HTTP headers and print a specific header value.

Arduino
http.begin("http://example.com");
http.addHeader([1], [2]);
String headerValue = http.header([3]);
Serial.println(headerValue);
Drag options to blanks, or click blank then click option'
A"Content-Type"
B"application/json"
D"Authorization"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header keys or values
Mixing up the order of key and value in addHeader