在 ColdFusion 中使用 PUT 请求创建 Wufoo Webhook

发布于 2024-09-28 11:41:32 字数 2670 浏览 3 评论 0原文

我在向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

窝囊感情。 2024-10-05 11:41:32

Wufoo 要求参数“作为 post 参数传递给Web Hook API”。尝试对请求正文使用 application/x-www-form-urlencoded 编码。在 ColdFusion 中,您可以使用 来执行此操作。

<cfhttpparam type="FormField" name="url" value="#local.webHookURL#" />
<cfhttpparam type="FormField" name="handshakeKey" value="#local.webHookKey#" />

然而,ColdFusion 使用 PUT 方法拒绝这种技术。您可以使用以下方法自己对主体进行编码:

<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded; charset=UTF-8" />
<cfhttpparam type="body" value="url=#UrlEncode(local.webHookURL)#&handshakeKey=#UrlEncode(local.webHookKey)#" />

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" />.

<cfhttpparam type="FormField" name="url" value="#local.webHookURL#" />
<cfhttpparam type="FormField" name="handshakeKey" value="#local.webHookKey#" />

However, ColdFusion rejects this technique with PUT methods. You can encode the body yourself using:

<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded; charset=UTF-8" />
<cfhttpparam type="body" value="url=#UrlEncode(local.webHookURL)#&handshakeKey=#UrlEncode(local.webHookKey)#" />
梦旅人picnic 2024-10-05 11:41:32

在ColdFusion中,一般来说,变量名是不区分大小写的,并且是大写的。

<cfset local.request = {
  url = local.webHookURL,
  handshakeKey = local.webHookKey
} />

这将为您提供一个带有键 URLHANDSHAKEKEY 的结构。

在 Web 上,大概包括 Wufoo REST API,键是区分大小写的。在这种情况下,Wufoo 接受urlhandshakeKey元数据 - 在该外壳中

在 ColdFusion 中,带有结构体 put(赋值)的关联数组表示法可以让您保持所需的精确大小写。

<cfset local.request = { } />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />

这将为您提供一个带有键 urlhandshakeKey 的结构。

In ColdFusion, generally, variable names are case-insensitive and uppercase.

<cfset local.request = {
  url = local.webHookURL,
  handshakeKey = local.webHookKey
} />

This gives you a struct with keys URL and HANDSHAKEKEY.

On the Web, presumably including with the Wufoo REST API, keys are case-sensitive. In this case, Wufoo accepts keys url, handshakeKey, and metadata - in that casing.

In ColdFusion, associative-array notation with struct puts (assignments) lets you keep the precise casing you want.

<cfset local.request = { } />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />

This gives you a struct with keys url and handshakeKey.

残疾 2024-10-05 11:41:32

不熟悉这个 api,但是 url、握手密钥等应该是 post params 的形式吗?

以下参数必须是
作为 post 参数传递到 Web
钩子API

url - 此必需参数
代表您服务器上的 URL
当新的
条目已提交。我们确实验证了
URL 并拒绝格式错误的 URL。

handshakeKey - 此可选参数
Web Hook 中描述了
集成开始
文档。

metadata=true - 此可选值
参数要一起发送的 Web Hook
表单/字段

我读到的方式,看起来他们在问
对于每个参数。

该错误表明它找不到 URL 参数,也许就是这样。

Not familiar with this api but should the url, handshakekey, etc be form post params?

The following parameters must be
passed as post parameters to the Web
Hook API

url - this required parameter
represents the URL on your server that
the Web Hook will call when a new
entry is submitted. We do validate the
URL and reject malformed URLs.

handshakeKey - this optional parameter
is described in the Web Hook
integration getting started
documentation.

metadata=true - this optional value
parameter the Web Hook to send along
form/field

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文