Specific's on sending HTML over HTTP/TCP

AgentSmithers
Posts: 195
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Specific's on sending HTML over HTTP/TCP

Postby AgentSmithers » Tue Mar 06, 2018 5:14 pm

Hi Everyone, Anyone know the specific's on the best way to send an HTML page using two espconn_send calls. Right now I have to doublebuffer to send the Data with the correct header. I would like to just send the header string without having to get it all into one huge buffer and spitting it out, The code below are examples of what I've tried to get it to work both using keep alive and using close to let the HTTP client know when I'm done sending the data be only to fail. Any thing I am missing?

Code: Select all

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: Select all

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);
}

Who is online

Users browsing this forum: No registered users and 319 guests