내 안드로이드 장치로 일부 LED를 토글하고 싶습니다. 이 LED는 내 Arduino의 디지털 핀에 연결되어 있으며이 핀은 또한 ESP8266에 연결됩니다. 이제 ESP8266은 AccessPoint로 정의되었으며 내 태블릿은 HTTP 요청을 보낼 수 있습니다 (예 : http://192.168.4.1:80/?pin=11). 여기에 코드를 찾았습니다 http://allaboutee.com/2015/01/20/esp8266-android-application-for-arduino-pin-control/ESP8266 및 Arduino로 HTTP 응답을 작성하는 방법
잘 작동하지만 제 질문은 어떤 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);
}
가능한 헤더 필드 목록은 다음에서 찾을 수 있습니다. https://en.wikipedia.org/wiki/List_of_HTTP_header_fields – TeaAge