Python发送HTTP GET请求

import socket
host='testlws.sinaapp.com'
port=80
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
s.sendall("GET / HTTP/1.1\r\nHost:testlws.sinaapp.com\r\nConnection:Keep-Aliv\r\n\r\n")
d=s.recv(1024)

'HTTP/1.1 200 OK\r\nServer: nginx/1.2.2\r\nDate: Thu, 06 Jun 2013 11:16:43 GMT\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\nConnection: keep-alive\r\nvia: yq34\r\nSet-Cookie: saeut=CkMPIlGwb5tjBRoFGIA2Ag==; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/\r\n\r\n6\r\nindexx\r\n0\r\n\r\n'

你可能感兴趣的:(Python发送HTTP GET请求)