![](/img/trans.png)
[英]How to do a HTTP DELETE request with Python requests module without “Content-Length: 0”?
[英]How to do a HTTP DELETE request with Requests library
我正在使用請求包與toggl.com API進行交互。
我可以執行GET和POST請求:
payload = {'some':'data'}
headers = {'content-type': 'application/json'}
url = "https://www.toggl.com/api/v6/" + data_description + ".json"
response = requests.post(url, data=json.dumps(payload), headers=headers,auth=HTTPBasicAuth(toggl_token, 'api_token'))
但我似乎無法找到執行DELETE請求的方法。 這可能嗎?
使用requests.delete而不是requests.post
payload = {'some':'data'}
headers = {'content-type': 'application/json'}
url = "https://www.toggl.com/api/v6/" + data_description + ".json"
response = requests.delete(
url,
data=json.dumps(payload),
headers=headers,
auth=HTTPBasicAuth(toggl_token, 'api_token')
)
import requests
url = 'url.example.ap'
headers = {
'content-type': "multipart/form-data; boundary=---- ",
'X-Auth-Token': ""anytoken"",
'Cache-Control': "no-cache"
}
r = requests.delete(url, headers=headers)
n = os.write(sys.stdout.fileno(), r.content)
print r.content == r.text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.