Reputation: 57
I have an example of code that I want to learn from. When I save this code as a HTML file, the code shows instead of the h1. Why is this? Thank you.
HTTP/1.1 200 Ok
Server: Apache/2.2.3 (Red Hat)
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Wed, 11 Dec 2013 19:19:58 GMT
Date: Wed, 11 Dec 2013 19:39:44 GMT
Content-Length: 163
Content-Type: text/html
<!DOCTYPE html>
<html>
<head>
<title> Hello World Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
Upvotes: 1
Views: 62
Reputation: 107267
The example you have given seems to be a full HTTP payload, e.g. as captured via a network sniffer or browser debugging tool.
You shouldn't save the HTTP headers when saving the .html
file - these are an artifact of the HTTP protocol, and not of the .HTML
markup for rendering.
Just save the part after
<!DOCTYPE html>
Upvotes: 2
Reputation: 35453
Your problem is because your text contains the HTTP header info plus the HTML.
This is the HTTP header - do not put it in your HTML file;
HTTP/1.1 200 Ok
Server: Apache/2.2.3 (Red Hat)
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Wed, 11 Dec 2013 19:19:58 GMT
Date: Wed, 11 Dec 2013 19:39:44 GMT
Content-Length: 163
Content-Type: text/html
This is the HTML - put it in its own file, such as hello.html:
<!DOCTYPE html>
<html>
<head>
<title> Hello World Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
What you're seeing when you load your text is probably because your browser is seeing plain text at the beginning of your file, and so your browser is guessing that the file is plain text instead of HTML.
Upvotes: 2
Reputation: 44831
First, you shouldn't be saving the headers as part of the file. They are HTTP headers returned by a server, not part of the page itself. I'm talking about this:
HTTP/1.1 200 Ok
Server: Apache/2.2.3 (Red Hat)
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Wed, 11 Dec 2013 19:19:58 GMT
Date: Wed, 11 Dec 2013 19:39:44 GMT
Content-Length: 163
Content-Type: text/html
Second, please confirm that your extension is .htm or .html.
Finally, how are you viewing this? In a browser, text editor, or something else?
Upvotes: 0