我想使用HTTPoison Library在Elixir中执行以下命令.
$curl -X DELETE -H "expired: 1442395800" -H "signature: ******************" -d '{"api_key":"***************","delete_path":"*******","expired":"****"}' https://cdn.idcfcloud.com/api/v0/caches {"status":"success","messages":"We accept the cache deleted successfully."}
当我检查文档如何在HTTPoison中删除
def delete!(url,headers \\ [],options \\ []),do: request!(:delete,url,"",headers,options)
只需要url和header.那么我应该把请求体(json体在curl中)放在哪里?
在Elixir,我试过了
req_body = "{\"api_key\":\"#{api_key}\",\"delete_path\":\"#{delete_path}\",\"expired\":\"#{expired}\"}" url = "https://cdn.idcfcloud.com/api/v0/caches" response = HTTPoison.delete!(url,header,[req_body])
但似乎行不通.有人能说出正确的方法吗?
@R_403_323@
正如您所知,HTTPoison.delete!/ 3将发送一个“”作为帖子正文.如果一个正文对DELETE请求有效,那么之前就存在一些问题 – 见
Is an entity body allowed for an HTTP DELETE request?
req_body = "{\"api_key\":\"#{api_key}\",\"expired\":\"#{expired}\"}" url = "https://cdn.idcfcloud.com/api/v0/caches" response = HTTPoison.request!(:delete,req_body,header)
我已经回答了一个不同的问题,它提供了有关生成帖子体的更多信息 – Create Github Token using Elixir HTTPoison Library