Reputation: 11
I am using socket to visit a localhost website. Get the following error:
HTTP/1.1 408 Request Timeout
Content-Length: 0
Content-Type: text/plain
The socket code as below:
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()
Upvotes: 1
Views: 77
Reputation: 369064
HTTP request header should end with two newlines. If you send only one blank line, the server will wait until timeout.
mysock.send('GET http://localhost:8000/hello HTTP/1.0\r\n\r\n')
Upvotes: 1