zoukankan      html  css  js  c++  java
  • python——requests

    #!/usr/bin/env python
    # encoding: utf-8
    '''
    Module Description

    Created on Jul 31, 2019
    @author: user
    @change: Jul 31, 2019 user: initialization
    '''
    import json
    import httplib
    import requests

    def post_request(url, parameter):
    '''
    @summary:
    @param url: 'https://wup.roaddb.net:7001/api/login'
    @param parameter: e.g: {"username": user_email, "password": password}
    @return:
    '''
    req = requests.post(url, data=json.dumps(parameter), headers={"Content-Type": "application/json"})
    print "req:", req.text

    #获取返回码
    status_code = req.status_code

    #获取返回结果里面body的数据
    return_header = req.text

    #获取返回的json数据
    status_dict = req.json()

    def get_request(url):
    '''

    :return:
    '''
    req = requests.get(url)


    def request_get(url, user, password):
    '''
    @summary: Send GET request to server
    @param url: the url of the server
    @param user: the user name
    @param password: the password
    @return: return response string from server
    '''
    # add user authorization to request
    session = requests.Session()
    session.verify = False
    session.auth = (user, password)

    # return response body text
    return session.get(url, timeout=10).text

    def request_post(url, data, user, password):
    '''
    @summary: Send POST request to server
    @param url: the url of the server
    @param data: the data send to server
    @param user: the user name
    @param password: the password
    @return: return response code and content string from server
    '''
    # add user authorization to request
    session = requests.Session()
    session.auth = (user, password)

    # return response body text and status code
    result = session.post(url, data)
    return result.status_code, result.content

    if __name__ == '__main__':
    pass
  • 相关阅读:
    Configuring the launch of the remote virtual machine to debug
    java LimitedThreadPool
    java并发之SynchronousQueue实现原理
    java 线程池线程忙碌且阻塞队列也满了时给一个拒接的详细报告
    Java程序监控指标
    JDK提供的四种线程池
    Guava的Supplier实现单例
    JMM
    Dubbo源码解读:appendAnnotation [01]
    PCI(Payment Card Industry)合规
  • 原文地址:https://www.cnblogs.com/ting152/p/12580558.html
Copyright © 2011-2022 走看看