Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在post请求后检索服务器响应_Python_Sockets_Request - Fatal编程技术网

Python 如何在post请求后检索服务器响应

Python 如何在post请求后检索服务器响应,python,sockets,request,Python,Sockets,Request,发送post请求后,我如何知道服务器响应 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 wi

发送post请求后,我如何知道服务器响应

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&currentSelecter=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)

好的,通过
recv()
-ing在你用来发送请求的套接字对象上。@PresidentJamesK.Polk谢谢你解决了