ESP8266 Developer Zone The Official ESP8266 Forum 2018-03-06T17:14:31+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=9303 2018-03-06T17:14:31+08:00 2018-03-06T17:14:31+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9303&p=19541#p19541 <![CDATA[Specific's on sending HTML over HTTP/TCP]]>

Code:

LOCAL void ICACHE_FLASH_ATTR HttpSendWithHeader(struct espconn * WifiScanConfigConnection, unsigned char * LFormatedHTMLPage)
{
   //os_printf("Attaching header and sending\r\n");
   os_memset(FormatedHTMLPageWithHttpHeader, 0, HTMLSIZE);
   os_sprintf(FormatedHTMLPageWithHttpHeader, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nConnection: close\r\n\r\n", os_strlen(LFormatedHTMLPage));
   os_strcat(FormatedHTMLPageWithHttpHeader, LFormatedHTMLPage);
   espconn_send(WifiScanConfigConnection, (uint8*)FormatedHTMLPageWithHttpHeader, os_strlen(FormatedHTMLPageWithHttpHeader));
   os_printf("HTTP Response sent bytes: %d\r\n", os_strlen(LFormatedHTMLPage));
}


vs.

Code:

LOCAL void ICACHE_FLASH_ATTR HttpSendWithHeader(struct espconn * WifiScanConfigConnection, unsigned char * LFormatedHTMLPage)
{
   //os_printf("Attaching header and sending\r\n");
   os_memset(FormatedHTMLPageWithHttpHeader, 0, HTMLSIZE);
   os_sprintf(FormatedHTMLPageWithHttpHeader, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nConnection: keep-alive\r\n\r\n", os_strlen(LFormatedHTMLPage));
   //os_strcat(FormatedHTMLPageWithHttpHeader, LFormatedHTMLPage);
   espconn_set_keepalive(WifiScanConfigConnection, ESPCONN_KEEPCNT, NULL);
   espconn_send(WifiScanConfigConnection, (uint8*)FormatedHTMLPageWithHttpHeader, os_strlen(FormatedHTMLPageWithHttpHeader));
   os_printf("HTTP HEADER Response sent bytes: %d\r\n", os_strlen(FormatedHTMLPageWithHttpHeader));   
   espconn_send(WifiScanConfigConnection, (uint8*)LFormatedHTMLPage, os_strlen(LFormatedHTMLPage));
   os_printf("HTTP BODY Response sent bytes: %d\r\n", os_strlen(LFormatedHTMLPage));
   //espconn_disconnect(WifiScanConfigConnection);
}

Statistics: Posted by AgentSmithers — Tue Mar 06, 2018 5:14 pm


]]>