python requests.post带head和body的实例

yipeiwu_com6年前Python基础

如下所示:

# coding = utf-8
import requests
import json

host = "http://47.XX.XX.XX:30000"
endpoint=r"/api/v1/carXX/addCarXX"

url = ''.join([host,endpoint])
headers = \
  {
    "X-Member-Id": "23832170000",
    "X-Region": "1100000",
    "X-Channel": "01",
    "Content-Type": "application/json;charset=UTF-8"
  }
body = \
  {
    "designerId": "1111",
    "itemQuantity": 1,
    "sku": "000100000"
  }
r = requests.post(url,headers=headers,data=json.dumps(body))
#r = requests.post(url,headers=headers,json=body)
print r.text
print r.url

以上这篇python requests.post带head和body的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解从Django Rest Framework响应中删除空字段

我使用django-rest-framework开发了一个API. 我正在使用ModelSerializer返回模型的数据. models.py class MetaTags(mod...

python调用matlab的m自定义函数方法

项目信号处理和提取部分用到了matlab,需要应用到工程中方便研究。用具有万能粘合剂之称的“Python”。具体方法如下: 1.python中安装mlab 下载https://pypi...

完美解决Python2操作中文名文件乱码的问题

完美解决Python2操作中文名文件乱码的问题

Python2默认是不支持中文的,一般我们在程序的开头加上#-*-coding:utf-8-*-来解决这个问题,但是在我用open()方法打开文件时,中文名字却显示成了乱码。 我先给大家...

python根据url地址下载小文件的实例

如下所示: #########start根据url地址下载小文件############ def download_little_file(from_url,to_path): c...

对python3标准库httpclient的使用详解

如下所示: import http.client, urllib.parse import http.client, urllib.parse import random USER...