需要注意http1.1和http1.0的區別

http1.1要加上Host才可以, http1.0則不用

#!/usr/bin/env python

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('172.17.9.9', 80))
#sock.send('GET / HTTP/1.0\r\n\r\n')
sock.send("GET %s HTTP/1.1\r\nHost: %s\r\n\r\n" % ('/', '172.17.8.191'))
data = sock.recv(80960)
print len(data)




Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐