python requests set headers and post request body x-www-form-urlencoded

1.application/json: It is an identification method submitted in JSON format. marked in the request header.
2.application/x-www-form-urlencoded: This is the representation of the form when the form is submitted.
For example, in our ajax submission, if the dataType is json, then the request header is application/json, and our usual form submission is application/x-www-form-urlencoded. You can see it in your browser console.
3.multipart/form-data
This is another common way of POST data submission. When we use the form to upload files, we must make the enctyped of the form equal to this value
4.text/xml
It is a remote calling specification that uses HTTP as the transmission protocol and XML as the encoding method

#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",
    #Hm_lvt_d47d0c2743e9b14d07c86e077d6bdaa2=1524647779,1524651322,1525633526,1525673504; Hm_lpvt_d47d0c2743e9b14d07c86e077d6bdaa2=1525674666", Hm_lvt_d47d0c2743e9b14d07c86e077d6bdaa2=1524647779,1524651322,1525633526,1525673504; Hm_lpvt_d47d0c2743e9b14d07c86e077d6bdaa2=1525674666",
    "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)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325817742&siteId=291194637