zoukankan      html  css  js  c++  java
  • request取值相关

    发送数据格式与对应接收方法

    方式一:
        request.post(
            url='xx',
            data={'k1':'v1,'k2':'v2'}
        )
        #数据:  POST /  http1.1
    Content-type:urlencode-form.......
    
    k1=v1&k2=v2
    
        
        request.POST必然可以获取到值。
            - content-type: urlencode-form
            - 数据格式:k1=v1&k2=v2
    
    方式二:
        request.post(
            url='xx',
            json={'k1':'v1,'k2':'v2'}
        )
        #数据:  POST /  http1.1
    Content-type:application/json....
    
    {'k1':'v1,'k2':'v2'}
        request.body取到的数据是字节格式的,需要转化为字符串,然后进行反序列化就能拿到子弹
            字节 = {'k1':'v1,'k2':'v2'}
            字节转换字符串
            反序列化字符串 -> 字典 
        
        request.POST必然不可以获取到值的情况:
            - content-type: urlencode-form
            - 数据格式:k1=v1&k2=v2

     知识点:

    在chrome中如果看到的数据是Form Data ,那么它的数据是如下格式构造出来的
        Form Data:
            phone=861513125555&password=12312312312&oneMonth=1
            
            进行数据伪造的时候:
            reqeusts.post(
                url=url,
                data={
                    phone:123123123123,
                    password:asdfasdf
                }
            )
        
        如果看到的数据为Request Payload:
            {"BaseRequest":{"Uin":981579400,"Sid":"zWvteTWqBop4heoT","Skey":"@crypt_2ccf8ab9_a710cf413c932e201987599558063c8e","DeviceID":"e358217921593270"},"Msg":{"Type":1,"Content":"test","FromUserName":"@60eef3f2d212721fda0aae891115aa7a","ToUserName":"@@6a5403f510a3192454ed1afebd78ec6033d5057c9038d7b943b201f0a74987d4","LocalID":"15300708105840758","ClientMsgId":"15300708105840758"},"Scene":0}
        
            进行数据伪造的时候:
            reqeusts.post(
                url=url,
                json={
                    phone:123123123123,
                    password:asdfasdf
                }
            )
            
            或者:
            reqeusts.post(
                url=url,
                data=bytes(json.dumps({
                    phone:123123123123,
                    password:asdfasdf
                }),encoding=utf-8)
            )

    发送的数据与对应发过去的格式:

    data:
        request.post(
            url='xx',
            data={'k1':'v1,'k2':'v2'}
        )
        #数据:  POST /  http1.1
    ....
    
    k1=v1&k2=v2
        
        
        request.post(
            url='xx',
            data=json.dumps({'k1':'v1,'k2':'v2'})
        )
        #数据:  POST /  http1.1
    ....
    
    {'k1':'v1,'k2':'v2'}
        
        request.post(
            url='xx',
            data=b'asdfasdf'
        )
        #数据:  POST /  http1.1
    ....
    
    'asdfasdf'
    json:
        request.post(
            url='xx',
            json={'k1':'v1,'k2':'v2'}
        )
        #数据:  POST /  http1.1
    Content-type:application/json....
    
    {'k1':'v1,'k2':'v2'}
  • 相关阅读:
    为什么switch里的case没有break不行
    CLS的探索:Python如何让日志免费云化
    做一次“黑客“,入侵一次自己的服务器
    斥资288买了三年服务器之后应该如何配置
    Scrapy入门到放弃01:开启爬虫2.0时代
    c#自制抽奖小程序
    c#中的几种Dialog
    解决数据库排序空值排在前问题
    Oracle 数据库添加定时事件
    FileReader 对象实现图片预览
  • 原文地址:https://www.cnblogs.com/zh-xiaoyuan/p/13288163.html
Copyright © 2011-2022 走看看