这是curl命令:
curl -H "X-API-TOKEN: <API-TOKEN>" 'http://foo.com/foo/bar' --data #
Run Code Online (Sandbox Code Playgroud)
让我解释一下数据的含义
POST /foo/bar
Input (request JSON body)
Name Type
title string
body string
Run Code Online (Sandbox Code Playgroud)
所以,基于此...我想:
curl -H"X-API-TOKEN:"' http://foo.com/foo/bar'--data '{"title":"foobar","body":"这个身体同时具有"双重"和'单'引用"}'
不幸的是,我也无法解决这个问题(比如来自cli的curl)虽然我想用python发送这个请求.我该怎么做呢?
can*_*tas 27
使用标准的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
Run Code Online (Sandbox Code Playgroud)
或者如果你想使用名为"请求"的漂亮的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)
Run Code Online (Sandbox Code Playgroud)