我想使用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])
但似乎行不通.有人能说出正确的方法吗?
解决方法
正如您所知,HTTPoison.delete!/ 3将发送一个“”作为帖子正文.如果一个正文对DELETE请求有效,那么之前就存在一些问题 – 见
Is an entity body allowed for an HTTP DELETE request?
但是,您可以绕过此功能并直接调用request!/ 5:
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。