zoukankan      html  css  js  c++  java
  • Python发送四种格式的post请求的代码样例

    x-www-form-urlencoded:

    path = "/api/v1/topics/update"
    params={'accesstoken':'d38a77f0-6f29-45cd-8d49-f72f15b98fd2','topic_id':'5c89021773798770589936b0','title':'hahaha','tab':'share','content':'hahaha'}
    response_text = requests.post(url=self.url+path, data=params).text

    # 将响应内容转换成字典格式
    response_dict = json.loads(response_text)
    # 获取response message字段的值
    response_message = response_dict['topic_id']
    # 判断message的值
    self.assertEqual(response_message, '5c89021773798770589936b0', msg='topic返回值不对')

    form-data:

    # post request method
    response = requests.post(url=url + path, params=params,headers=headers)
    # Is the return status code 200?
    self.assertEqual(response.status_code, 200, msg="The status code is not 200")
    # Is the return message SUCCESS?
    response_text = requests.post(url=url + path, params=params,headers=headers).text
    # Convert response content into dictionary format.
    response_dict = json.loads(response_text)
    # Gets the value of the response message.
    response_message = response_dict['message']
    # Determine the value of message.
    self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS')
    #Print response text.
    print(response.text)
  • 相关阅读:
    leftpad填充函数;
    overfllow的解析
    append与after
    数组扁平话的N种解法;
    关于webapi调用wcf并发假死的分析
    C#金额数字转换中文繁体
    关于ios的IDFA
    Windows下为MySQL做定时备份
    [System.OutOfMemoryException] {函数求值已禁用,因为出现内存不足异常。
    mvc 捕获404和500 等
  • 原文地址:https://www.cnblogs.com/lanyy/p/10526698.html
Copyright © 2011-2022 走看看