Postman的Post请求方式的四种类型的数据

  • 1. form-data

就是http请求中的multipart/form-data,它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开。既可以上传键值对,也可以上传文件。当上传的字段是文件时,会有content-type来说明文件类型;content-disposition用来说明字段的一些信息;由于有boundary隔离,所以multipart/form-data既可以上传文件,也可以上传键值对,它采用了键值对的方式,所以可以上传多个文件。

  • 2.x-www-form-urlencoded:

就是application/x-www-from-urlencoded,会将表单内的数据转换为键值对

  • 3.raw

可以上传任意格式的文本,可以上传text、json、xml、html等

  • 4.binary

相当于content-type:application/octet-stream,从字面意思得知,只可以上传二进制数据,通常用来上传文件,由于没有键值,所以,一次只能上传一个文件。

python requests 设置headers 和 post请求体x-www-form-urlencoded

1.application/json:是JSON格式提交的一种识别方式。在请求头里标示。

2.application/x-www-form-urlencoded : 这是form表单提交的时候的表示方式。 比如我们ajax提交,如果dataType是json,那么请求头就是application/json,而我们平常的form提交那么就是application/x-www-form-urlencoded,自己浏览器控制台看看就知道了。

3.multipart/form-data:这又是一个常见的 POST 数据提交的方式。我们使用表单上传文件时,必须让 form 的 enctyped 等于这个值

4.text/xml :它是一种使用 HTTP 作为传输协议,XML 作为编码方式的远程调用规范

#coding:utf-8
from fake_useragent import UserAgent;
import requests


ua=UserAgent()
headers={
    "Proxy-Connection": "keep-alive",
    "Pragma": "no-cache",
    # "DNT":"1",
    "User-Agent":ua.random,
    "Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4",
    "Referer": "www.huixiaoer.com",
    "Accept-Charset": "gb2312,gbk;q=0.7,utf-8;q=0.7,*;q=0.7",
    "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Encoding":"gzip, deflate, sdch",
    "Cache-Control":"max-age=0",
    "Connection":"keep-alive",
    "Content-Type":"application/x-www-form-urlencoded",
    "Host":"www.huixiaoer.com",
    "Upgrade-Insecure-Requests":"1",
    "X-Requested-With":"XMLHttpRequest"
}

cookies={
        "pgv_pvi":"9755294720",
        "aliyungf_tc":"AQAAAIEbHSUhVA4ATkxVeHH7o+UfJUCq",
        "acw_tc":"AQAAAFesTD4BeQ4ATkxVeNrQ4zX/wI03",
        "PHPSESSID":"flc3hhtdbcgvr4pgekhvk7rrb1",
        "pgv_si":"s7094364160",
        "city":"440100",
        "_ga":"GA1.2.968334469.1525633526",
        "_gid":"GA1.2.1982983394.1525633526",
        "sensorsdata2015jssdkcross":"%7B%22distinct_id%22%3A%22162fc16d967476-00a0ee49af4a81-5d4e211f-1049088-162fc16d9684e5%22%2C%22%24device_id%22%3A%22162fc16d967476-00a0ee49af4a81-5d4e211f-1049088-162fc16d9684e5%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_utm_source%22%3A%22bdpp_web%22%2C%22%24latest_utm_medium%22%3A%22ppc%22%2C%22%24latest_utm_campaign%22%3A%22title_20180223%22%7D%7D",
        "Hm_lvt_d47d0c2743e9b14d07c86e077d6bdaa2":"1524647779,1524651322,1525633526,1525673504",
        "Hm_lpvt_d47d0c2743e9b14d07c86e077d6bdaa2":"1525674666"
}

datas={
    'conditions':'{"city_code":"440100","hid":-1,"capacity":-1,"type_code":-1,"tag":-1,"keyword":-1,"key":-1,"lat":"0","lng":"0","center_name":-1,"has_package":-1,"has_special":0,"has_conference":1,"order":-1,"dur":-1,"bud":-1,"page":1,"num":"","cap_num":"","qt":0}'
}

url="http://www.huixiaoer.com/so-api/ajax-get-so-data"
session=requests.session()
requ=session.post(url,data=datas,headers=headers,cookies=cookies)
res=requ.text
print(res)

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券