Python implements batch post JSON data test __JS

Source: Internet
Author: User
Tags sendmsg

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.