Go Down

Topic: ESP8266 Can someoen explain what client.print does? (Read 312 times) previous topic - next topic

Lliam

I was looking at a simple web_server code that fetches an index.txt and reads the values inside the text. I was curious about the purpose of client.print and the following lines of code. Could someone provide me with an explanation (explain like I am 5)

Code: [Select]
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(500);


Why do I need:

Code: [Select]
"Host: " + host + "\r\n" +

It seems not to work without that, but some examples that I have read online emit those lines . This is an example from the client.available reference.
Code: [Select]
    client.println("GET /search?q=arduino HTTP/1.0");

Koepel

It was not needed in the past, and if you use HTTP/1.0 you might not need it.

According to Wikipedia, it is "Mandatory since HTTP/1.1" : https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

Go Up