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)
  • 相关阅读:
    Linux监控内核SNMP计数器
    wireshark使用手册
    【LinuxShell】echo用法详解
    【Coredump】调试之旅
    汇编指令
    从零开始学Java (五)条件选择
    从零开始学Java (四)输入输出
    Dart基础
    树相关
    递归简介
  • 原文地址:https://www.cnblogs.com/lanyy/p/10526698.html
Copyright © 2011-2022 走看看