【发布时间】:2016-07-05 17:57:30
【问题描述】:
我想用我的 Android 设备切换一些 LED。这些 LED 连接到我的 Arduino 的数字引脚,该引脚也连接到 ESP8266。现在,我的 ESP8266 被定义为一个接入点,我的平板电脑可以发送 HTTP 请求(例如http://192.168.4.1:80/?pin=11)。 我在这里找到了代码http://allaboutee.com/2015/01/20/esp8266-android-application-for-arduino-pin-control/
它工作正常,但我的问题是应该使用哪个 HTTP 标头字段?在这段代码中,他使用了一些(例如 Content-Length),但还有更多可能(日期、服务器、内容语言……)。
这些字段是可选的还是必须使用其中的哪些来构建正确的响应?
这是一段我看不懂的代码:
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);
}
【问题讨论】:
-
可以在此处找到可能的标头字段列表:en.wikipedia.org/wiki/List_of_HTTP_header_fields
标签: http arduino http-headers esp8266