gpt4 book ai didi

coldfusion - CFHTTP 和 CloudFlare API : DELETE purge_everything not working

转载 作者:行者123 更新时间:2023-12-04 21:10:37 25 4
gpt4 key购买 nike

有没有其他人能够使用 CFHTTP DELETE purge_everything ?
我似乎无法让 ColdFusion CFHTTP 成功清除 CloudFlare 区域的缓存。但是我可以做其他事情,比如列表区域等。所以我知道我可以成功地将 CFHTTP 连接到 CloudFlare 的 API。

这是 curl 命令,它有效:

curl -svX DELETE -H 'X-Auth-Email: a@b.c' -H 'X-Auth-Key: XYZ' https://api.cloudflare.com/client/v4/zones/xxxxxxx/purge_cache  -H 'Content-Type: application/json' --data '{"purge_everything":true}'

返回的错误是:

{"success":false,"errors":[{"code":1012,"message":"Request must contain one of \"purge_everything\" or \"files\", or \"tags"}],"messages":[],"result":null}



我尝试了很多代码组合......这些是我尝试过的不同变量:

<cfset stFields = '{"purge_everything":true}'>
<cfset stFieldsJson = {"purge_everything":true}>
<cfset stFieldsJson2 = {
"fields" : {
"purge_everything" : true
}
}>
<cfset stFieldsJson3 = {
"purge_everything" : true,
"fields" : {
"purge_everything" : true
}
}>

<cfset tmp = {} />
<cfset tmp['purge_everything'] = true />

......这里是我所做的一些不同的调用组合......

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare"  charset="utf-8">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=utf-8">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value="#serializeJson(stFieldsJson)#" encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare" charset="utf-8">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=utf-8">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value="#serializeJson(stFieldsJson2)#" encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value="#serializeJson(stFieldsJson3)#" encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value="#serializeJson(tmp)#" encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare" charset="utf-8">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=utf-8">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value='{"purge_everything":true}' encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare" charset="utf-8">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=utf-8">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value='"purge_everything":true' encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

<cfhttp url="https://api.cloudflare.com/client/v4/zones/4da78b2707f9753eb79a93d505b4d0d3/purge_cache" method="DELETE" result="cFlare" charset="utf-8">
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=utf-8">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value='purge_everything' encoded="false">
</cfhttp>
<cfdump var="#cFlare#"><Cfflush>

我也试过在所有地方使用和不使用 'Encoded' Body 属性,使用和不使用 'Charset' 属性。

任何帮助表示赞赏。

最佳答案

不确定您正在运行哪个版本的 CF。但是,我怀疑您没有做错任何事情,而是<cfhttp>method="DELETE"时根本不发送正文,鉴于错误消息,这是有道理的。

测试它的一个简单方法是指向您的 <cfhttp>调用本地 CF 服务器上的测试页面。在测试页转储 GetHttpRequestData()因此您可以查看实际提交的标题和内容。 (另一种选择是在开放端口上使用 built in TCPMonitor,它提供了有关请求和响应的更多详细信息。但是,对于这种情况,第一种方法最简单。)

测试页

<!--- echo request headers and content --->
<cfdump var="#getHTTPRequestData()#">

请求
<!--- simulate request --->
<cfset requestBody["purge_everything"] = true>
<cfhttp url="http://localhost/testPage.cfm" method="DELETE" result="cFlare" charset="utf-8" >
<cfhttpparam type="header" name="X-Auth-Email" value="a@b.c">
<cfhttpparam type="header" name="X-Auth-Key" value="XYZ">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=utf-8">
<cfhttpparam type="header" name="accept" value="*/*">
<cfhttpparam type="body" value="#serializeJson(requestBody)#" encoded="false">
</cfhttp>

<!--- display request headers and content --->
<cfoutput>#cFlare.fileContent#</cfoutput>

注意当 method="DELETE" 时内容或正文为空?但是,将其更改为 method="POST"并且内容神奇地出现。

GetHttpRequestData() - Method=DELETE

Sending a body with a DELETE request应该是有效的,所以这听起来像是一个错误。如果是这样,您将需要找到不同的工具来发出 http 请求,例如从 cfexecute 调用 curl.exe。 ,或者使用像 cfx_http5 这样的自定义标签,或者像 URLConnection 那样使用 java 类或 Apache's HTTPClient .

关于coldfusion - CFHTTP 和 CloudFlare API : DELETE purge_everything not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35305341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com