我使用socket访问localhost网站。收到以下错误:
HTTP/1.1 408 Request Timeout
Content-Length: 0
Content-Type: text/plain
套接字代码如下:
import socket
mysock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysock.connect(('0.0.0.0',8080))
mysock.send('GET http://localhost:8080/hello HTTP/1.0\r\n')
while True:
data = mysock.recv(512)
if (len(data)<1):
break
print data
mysock.close()
答案 0 :(得分:1)
HTTP请求标头应以两个换行符结尾。如果只发送一个空行,服务器将等到超时。
mysock.send('GET http://localhost:8000/hello HTTP/1.0\r\n\r\n')