在 ColdFusion 中使用 PUT 请求创建 Wufoo Webhook
我在向 Wufoo 构建正确的 PUT 请求 时遇到问题。
在我的所有尝试中,我看到相同的错误:
404 WebHook 必须包含 url 参数。
这是 JSON 数据类型的版本:
<cfset local.action = "forms/#local.formHash#/webhooks.json" />
<cfset local.request = {"url" : local.webHookURL, "handshakeKey" : local.webHookKey} />
<cfset local.request["handshakeKey"] = local.webHookKey />
<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=UTF-8" />
<cfhttpparam type="body" value="#SerializeJSON(local.request)#" />
</cfhttp>
使用 file
时出现相同的失败:
<cfset local.action = "forms/#local.formHash#/webhooks.json" />
<cfset local.request = {"url" : local.webHookURL, "handshakeKey" : local.webHookKey} />
<cffile action="write" file="#GetTempDirectory()#webhook.json" output="#SerializeJSON(local.request)#">
<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=UTF-8" />
<cfhttpparam type="file" mimetype="application/json" name="json" file="#GetTempDirectory()#webhook.json" />
</cfhttp>
更新:
为了使代码在 ACF 中工作(我的代码仅在 Railo 中工作),请使用以下语法进行请求:
<cfset local.request = {} />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />
两种方法都应生成具有区分大小写键的相同 JSON。
我还尝试过 XML 数据类型:
<cfset local.action = "forms/#local.formHash#/webhooks.xml" />
<cfsavecontent variable="putXML">
<cfoutput>
<?xml version="1.0" encoding="UTF-8"?>
<WebHookPutRequest>
<url>#XMLFormat(local.webHookURL)#</url>
<handshakeKey>#XMLFormat(local.webHookKey)#</handshakeKey>
</WebHookPutRequest>
</cfoutput>
</cfsavecontent>
<cffile action="write" file="#GetTempDirectory()#webhook.xml" output="#Trim(putXML)#">
<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
<cfhttpparam type="header" name="Content-Type" value="application/xml; charset=UTF-8" />
<cfhttpparam type="body" value="#putXML#" />
</cfhttp>
这里我不确定我的 XML 是否正确,但对于 JSON 来说一切都应该没问题。
有什么想法我的代码有什么问题吗?
提前致谢。
I'm having troubles with building correct PUT request to the Wufoo.
In all my attempts I see the same error:
404 A WebHook must contain a url parameter.
Here is the version with JSON data type:
<cfset local.action = "forms/#local.formHash#/webhooks.json" />
<cfset local.request = {"url" : local.webHookURL, "handshakeKey" : local.webHookKey} />
<cfset local.request["handshakeKey"] = local.webHookKey />
<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=UTF-8" />
<cfhttpparam type="body" value="#SerializeJSON(local.request)#" />
</cfhttp>
Same failure when using file
:
<cfset local.action = "forms/#local.formHash#/webhooks.json" />
<cfset local.request = {"url" : local.webHookURL, "handshakeKey" : local.webHookKey} />
<cffile action="write" file="#GetTempDirectory()#webhook.json" output="#SerializeJSON(local.request)#">
<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
<cfhttpparam type="header" name="Content-Type" value="application/json; charset=UTF-8" />
<cfhttpparam type="file" mimetype="application/json" name="json" file="#GetTempDirectory()#webhook.json" />
</cfhttp>
UPDATE:
To make the code working in ACF (my code works in Railo only) use this syntax for request:
<cfset local.request = {} />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />
Both methods should produce same JSON with case-sensitive keys.
Also I've tried the XML data type:
<cfset local.action = "forms/#local.formHash#/webhooks.xml" />
<cfsavecontent variable="putXML">
<cfoutput>
<?xml version="1.0" encoding="UTF-8"?>
<WebHookPutRequest>
<url>#XMLFormat(local.webHookURL)#</url>
<handshakeKey>#XMLFormat(local.webHookKey)#</handshakeKey>
</WebHookPutRequest>
</cfoutput>
</cfsavecontent>
<cffile action="write" file="#GetTempDirectory()#webhook.xml" output="#Trim(putXML)#">
<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
<cfhttpparam type="header" name="Content-Type" value="application/xml; charset=UTF-8" />
<cfhttpparam type="body" value="#putXML#" />
</cfhttp>
Here I'm not sure if my XML is correct, though for JSON everything should be fine.
Any ideas what's wrong with my code?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Wufoo 要求参数“作为 post 参数传递给Web Hook API”。尝试对请求正文使用
application/x-www-form-urlencoded
编码。在 ColdFusion 中,您可以使用
来执行此操作。然而,ColdFusion 使用
PUT
方法拒绝这种技术。您可以使用以下方法自己对主体进行编码:Wufoo asks for the parameters to be "be passed as post parameters to the Web Hook API". Try using the
application/x-www-form-urlencoded
encoding for the body of the request. In ColdFusion, you can do this with<cfhttpparam type="FormField" />
.However, ColdFusion rejects this technique with
PUT
methods. You can encode the body yourself using:在ColdFusion中,一般来说,变量名是不区分大小写的,并且是大写的。
这将为您提供一个带有键
URL
和HANDSHAKEKEY
的结构。在 Web 上,大概包括 Wufoo REST API,键是区分大小写的。在这种情况下,Wufoo 接受键
url
、handshakeKey
和元数据
- 在该外壳中。在 ColdFusion 中,带有结构体 put(赋值)的关联数组表示法可以让您保持所需的精确大小写。
这将为您提供一个带有键
url
和handshakeKey
的结构。In ColdFusion, generally, variable names are case-insensitive and uppercase.
This gives you a struct with keys
URL
andHANDSHAKEKEY
.On the Web, presumably including with the Wufoo REST API, keys are case-sensitive. In this case, Wufoo accepts keys
url
,handshakeKey
, andmetadata
- in that casing.In ColdFusion, associative-array notation with struct puts (assignments) lets you keep the precise casing you want.
This gives you a struct with keys
url
andhandshakeKey
.不熟悉这个 api,但是 url、握手密钥等应该是 post params 的形式吗?
我读到的方式,看起来他们在问
对于每个参数。
该错误表明它找不到 URL 参数,也许就是这样。
Not familiar with this api but should the url, handshakekey, etc be form post params?
The way I read that, it looks like they are asking
for each of the params.
The error is suggesting it can't find the URL param, maybe that is it.