码迷,mamicode.com
首页 > Web开发 > 详细

http的请求流程

时间:2017-05-30 16:07:23      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:span   bin   href   http   连接   address   cep   服务   recv   

 1 # !/usr/bin/env python
 2 # coding:utf-8
 3 import socket
 4 
 5 
 6 def handle_request(client):
 7     buf = client.recv(1024)
 8     client.send("HTTP/1.1 200 OK\r\n\r\n")#状态码
    #client.send("Content-Type:text/html\r\n\r\n")#页面显示的格式
9 client.send("<a href=‘http://www.baidu.com‘>Hello, World</a>") 10 11 12 def main(): 13 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 14 sock.bind((localhost, 8080)) 15 sock.listen(5) 16 17 while True: 18 connection, address = sock.accept() 19 handle_request(connection)#当服务器接受请求并返回数据之后就断开连接不会出现交互的模式 20 connection.close() 21 22 23 if __name__ == __main__: 24 main()

 

http的请求流程

标签:span   bin   href   http   连接   address   cep   服务   recv   

原文地址:http://www.cnblogs.com/bill2014/p/6919931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!