The server often appears before the message will go down, the part of today's modified, the Python implementation of a batch post data test.
directly on the code. The URL is a beta, you see this code, should have no use, children's shoes need to have their own test URL oh.
(My test environment is, chat test, so you will see there is a req_id, to_id,msg three parts)
The first approach
#!/user/post_test.py
#coding =utf8
# by Kamy
import requests
url= "http://test.kamyshi.cn:8400/api/ sendmsg "
post={" req_id ": 1," to_id ":" 19,20,1000 "," msg_content ":" Test "}
loop=1000 for
i in range (0,loop) :
#上面如果写为 requests.session (). Post (URL, post) means that the data in the post is posted as a parameter. There is a difference between the two, look at the reader carefully. </span>
The second approach,
#coding: Utf-8
#postLib. py
Import urllib
import urllib2
import JSON
def http_post ():
url= " Http://test.kamyshi.cn</span>:8400/api/sendmsg "
values ={" req_id ": 1," to_id ":" 19,20,1000 "," msg_content ': ' Test '}
jdata = Json.dumps (values) # Format the data in JSON-formatted encoding
req = urllib2. Request (URL, jdata) # Generate full data for page requests
response = Urllib2.urlopen (req) # Send page request return
Response.read ( ) # Get the page information returned by the server
loop = 1000 for
i in range (0,loop):
print i
resp = http_post ()
#resp = htt P_post ()
#print resp