1

I want to toggle some LEDs with my Android device. These LEDs are connected to the digital Pins of my Arduino which is also connected to a ESP8266. Now, my ESP8266 is defined as an AccessPoint and my Tablet can send HTTP requests (e.g. http://192.168.4.1:80/?pin=11). I found the code here http://allaboutee.com/2015/01/20/esp8266-android-application-for-arduino-pin-control/

It works fine but my question is which HTTP header fields should be used? In this code he used some (e.g. Content-Length) but there are so much more possible (Date, Server, Content-Language,...).

Are these fields optional or which of these have to be used to build the right response?

Here is the piece of code I do not understand:

void sendHTTPResponse(int connectionId, String content)

{

 String httpResponse;
 String httpHeader;

 httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n"; 
 httpHeader += "Content-Length: ";
 httpHeader += content.length();
 httpHeader += "\r\n";
 httpHeader +="Connection: close\r\n\r\n";
 httpResponse = httpHeader + content + " ";
 sendCIPData(connectionId,httpResponse);

}

1

1 Answer 1

1

It largely depends on the client (i.e. consumer) which fields are required and which are mandatory.

The only one that is always required is "HTTP/1.1 200 OK". Of course you need to replace that status code if you're not sending an OK message.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the fast reply @MarcelStör ! So if I want to get a feedback on my Android device I need to have this "HTTP/1.1 200 OK" but the other fields are optional right ? And what does this HTTP/1.1 200 stand for ?
If your Android device expects HTTP then you need to declare the response as being an HTTP response. "HTTP/1.1" is the protocol and "200 OK" is the status. You also need to have the "\r\n" in place as shown in the example you posted. I suggest you familiarize yourself with code.tutsplus.com/tutorials/http-headers-for-dummies--net-8039.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.