简体   繁体   中英

how to create http headers from scratch

So, I made a simple socket server using python. And now I'm trying to structure a proper http response. However, I can't seem to find any sort of tutorial or spec that discusses how to format http responses.

Could someone point me to the right place?

RFC 2616

You may want to check out the following article:

The section Sample HTTP Exchange could help you getting started. Quoting:

The server should respond with something like the following, sent back through the same socket:

HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html
Content-Length: 1354

<html>
<body>
<h1>Happy New Millennium!</h1>
(more file contents)
  .
  .
  .
</body>
</html>

After sending the response, the server closes the socket.

The full protocol is defined in RFC 2616 if you want to get serious about this.

The urllib2 python standard library module helps you add http headers to your request.

Look in here for an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM