这里是curl命令:
curl -H "X-API-TOKEN: <API-TOKEN>" 'http://foo.com/foo/bar' --data #
让我来解释一下进入数据
POST /foo/bar
Input (request JSON body)
Name Type
title string
body string
所以,在此基础上..我想通:
卷曲-H “X-API-TOKEN:” 'http://foo.com/foo/bar' --data '{ “称号”: “foobar的”, “体”: “这身既有 ”双“ 和 '单' 引号”}'
不幸的是,我不能明白这一点,以及(就像从CLI卷曲)虽然我想用Python来发送该请求。我该怎么做呢?
随着标准Python httplib
和urllib
库,你可以做
import httplib, urllib
headers = {'X-API-TOKEN': 'your_token_here'}
payload = "'title'='value1'&'name'='value2'"
conn = httplib.HTTPConnection("heise.de")
conn.request("POST", "", payload, headers)
response = conn.getresponse()
print response
或者,如果你想使用名为"Requests"漂亮的HTTP库。
import requests
headers = {'X-API-TOKEN': 'your_token_here'}
payload = {'title': 'value1', 'name': 'value2'}
r = requests.post("http://foo.com/foo/bar", data=payload, headers=headers)