发送JSON数据:
curl -H "Content-Type:application/json" -k -u admin:1qaz2wsx -X PUT http://10.4.33.30:8080/cli/application/create --data '{"description":"My new application", "enforceCompleteSnapshots":"false", "name":"My Application zhaoyangjian", "notificationScheme":"Default Notification Scheme"}'
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import requests
import ssl
import json
s = requests.session()
s.auth = ('admin', '1qaz2wsx')
print s.headers
url = 'http://10.4.33.30:8080/cli/application/create'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
}
headers = {'Content-Type': 'application/json'} ## headers中添加上content-type这个参数,指定为json格式
datas={
"description":"Elasticsearch test",
"enforceCompleteSnapshots" :"false",
"name":"泰隆银行2018",
"notificationScheme":"1000" }
r=s.put(url,headers=headers, data=json.dumps(datas))
print r.text