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)
  • 相关阅读:
    2018-8-10-wpf-绑定-DataGridTextColumn-
    行踪隐藏 代理助手
    木马防杀 花指令 OllyDbg
    木马加壳
    elsave.exe日志清除
    黑客小工具
    WinRAR捆绑木马
    网页木马使用
    灰鸽子商业版用法
    黑洞远程连接
  • 原文地址:https://www.cnblogs.com/lanyy/p/10526698.html
Copyright © 2011-2022 走看看