发送发帖请求后,我如何知道服务器的响应?
import socket
import sys
import requests
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Socket successfully created"
except socket.error as err:
print "socket creation failed with error %s" %(err)
# default port for socket
port = 80
try:
host_ip = socket.gethostbyname('fr2.website.com')
except socket.gaierror:
# this means could not resolve the host
print "there was an error resolving the host"
sys.exit()
# connecting to the server
s.connect((host_ip, port))
print "host ip %s connected" %(host_ip)
headers = """\
POST /auth HTTP/1.1\r
Content-Type: {content_type}\r
Content-Length: {content_length}\r
Host: {host_ip}\r
Connection: close\r
\r\n"""
body = 'reloadToken=4bfc2a657de8b901fdb6990d4b9bf05a&setBid=true&ItemID=30&ItemType=Actionitem¤tSelecter=all&bidAmount=3&RTVT=main3d5b7b46e3f97a6d9b4a54da6d34&ajaxAction=biddOnItem'
body_bytes = body.encode('ascii')
header_bytes = headers.format(
content_type="application/x-www-form-urlencoded",
content_length=len(body_bytes),
host_ip=str(host_ip) + ":" + str(port)
).encode('iso-8859-1')
payload = header_bytes + body_bytes
s.sendall(payload)