Business need: I want to write a tanx simulator, to send a bid request to DSP.
Here's some code:
defPOSTDATATODSP (self,url,postdata): Headers= { 'Content-type':'Application/octet-stream', 'Connection':'keep-alive',} payload=PostData. Serializetostring () Conn=Httplib. Httpconnection (URL) conn.request (method='POST', url='/bid', BODY = payload, headers =headers) Response=Conn.getresponse ()PrintResponse.Statusif200 = =Response.Status:PrintResponse.read ()Print 'Send successfully' Else: Print 'Send failed'conn.close ()returnResponse.read ()
This code is wrong, just touch the internet industry, a bunch of not understand.
The boss pointed out: can only read once.
After the code has been modified:
defPOSTDATATODSP (self,url,postdata): Headers= { 'Content-type':'Application/octet-stream', 'Connection':'keep-alive',} payload=PostData. Serializetostring () Conn=Httplib. Httpconnection (URL) conn.request (method='POST', url='/bid', BODY = payload, headers =headers) Response=Conn.getresponse ()PrintResponse.Statusif200 = =Response.status:res=Response.read ()Print 'Send successfully' Else: Print 'Send failed'conn.close ()returnRes
Httpresponse.read ([Amt]): can only read once