python request 发送json数据

python request 发送json数据_第1张图片

python request 发送json数据_第2张图片

python request 发送json数据_第3张图片

python request 发送json数据_第4张图片


# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
s=requests.session()
#response = s.post(url, params=datas, **kwargs)
headers = {'Content-Type': 'application/json'}    ## headers中添加上content-type这个参数,指定为json格式
datas={
"title":"Elasticsearch test",
"name" :{  "first":"zhao",  "last":"zhoucui"  },
"publish_date":"2017-11-29",
"price":"1000"  }
response = s.post('http://192.168.137.2:9200/library/books/3000',headers=headers, data=json.dumps(datas))
print response.text




C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a16.py
{"_index":"library","_type":"books","_id":"3000","_version":8,"_shards":{"total":2,"successful":1,"failed":0},"created":true}


Process finished with exit code 0

你可能感兴趣的:(python,perl,curl,模拟各种请求)