Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By viktak
#45574 Hello Everyone,

Yesterday I came across a weird issue: I have an HTTP server running on the ESP. I store some html files on it, and when the user visits the ESP's IP address, a page is returned to the client. The problem is that this page only renders in Internet Explorer and Edge. on Firefox/Chrome/Safari the page appears as if I opened it in notepad, i.e. I can see the source, but not rendered HTML. I stripped down the code to a bare minimum, but still, the same error remains. Also, when looked at the pages straight from my pc, it renders correctly across all browsers. So clearly, the ESP has something to do with it.

This is the html code for reference:
Code: Select all<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <div class="container">
        <div class="jumbotron">
            <h1>Error</h1>
        </div>
        <div class="row">
            <div class="text-danger">Bad request.</div>
        </div>
    </div>
</body>
</html>


I wonder if any of you has come across this issue, and if yes, how you fixed it. Any pointers are appreciated!
User avatar
By viktak
#45590
martinayotte wrote:How do you send your HTML code to the client ?

To send HTML to the client I use the code for each line of the HTML file:
Code: Select allclient.print(lineOfHtml);

where client is defined as
Code: Select allWiFiClient client;


martinayotte wrote:What is in your HTML Header ?

The whole HTML file content is shown in my original post, so there's the header. Or you meant something else?

martinayotte wrote:Do you specify "Connection: close" in the header ?
(This is required, otherwise, some browser stays in infinite loop before rendering the page)

Can you please be a bit more specific? You also use the word header here and I have the feeling you don't mean the HTML header.
Just to clarify, I don't get an infinite loop on any browser: on Microsoft browsers the page loads fine, but on Chrome/Safari/Firefox, I can see the source.
User avatar
By martinayotte
#45612 Your HTML code mentioned above is the HTML body only, which does not includes any HTML header.

Your ESP Web Server should send an header before sending the body, something that look like :

Code: Select allHTTP/1.1 200 OK
Server: MyESPWebServer
Content-Length: 300
Connection: close
Content-Type: text/html;


If you don't do so, the different browsers can behave strangely from one to the other.
The most important thing is the 200 return code or 404 in case of page not found. The second is the content-length/content-type, and lastly the "connection: close".
Then, an empty line should follow the header before sending the body.
If you don't want to struggle with all those low level HTTP, you should better using ESP8266WebServer examples which will handle it for you.