在ColdFusion中创建具有PUT请求的Wufoo webhook
我正在为Wufoo构建正确的PUT request而遇到麻烦。在ColdFusion中创建具有PUT请求的Wufoo webhook
在我所有的努力我看到了同样的错误:
404 A WebHook must contain a url parameter.
这里是版本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>
UPDATE:
为了使代码在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一切都应该罚款。
任何想法我的代码有什么问题?
在此先感谢。
Wufoo asks for要将参数作为后置参数传递给Web Hook API。尝试使用application/x-www-form-urlencoded
编码作为请求的主体。在ColdFusion中,您可以使用<cfhttpparam type="FormField" />
执行此操作。
<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)#" />
在ColdFusion中,通常,变量名称不区分大小写,也不区分大小写。
<cfset local.request = {
url = local.webHookURL,
handshakeKey = local.webHookKey
} />
这给你的钥匙URL
和HANDSHAKEKEY
一个结构。
在Web上,可能包含Wufoo REST API,密钥区分大小写。在这种情况下,Wufoo accepts键url
,handshakeKey
和metadata
-在那个外壳。
在ColdFusion中,使用struct puts(assignments)的关联数组表示法可让您保持所需的精确外壳。
<cfset local.request = { } />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />
这给你的钥匙url
和handshakeKey
一个结构。
此建议在这里并不适用。请参阅更新的帖子 - 有关Railo与ACF的笔记。 – Sergii 2010-10-20 16:43:25
不熟悉这个API,但应该的URL,handshakekey等形式后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
我读的方式,它看起来像他们所要求 每个PARAMS的。
错误是暗示它找不到URL参数,也许就是这样。
当使用'
第二个建议工作!非常感谢,正义! – Sergii 2010-10-20 16:59:16
相关问题:我将如何发送带'DELETE' reqest的'hash'属性? 'body'类型不适用于DELETE,无法使'formField'工作。看到这个文档http://wufoo.com/docs/api/v3/webhooks/delete/ – Sergii 2010-10-20 17:19:17
ColdFusion理解'type =“FormField”'仅适用于'POST'请求。可以在'DELETE'请求中包含实体,就像'PUT'请求一样(参见http://*.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-请求),但是您将不得不使用相同的技术来包含主体,因为您需要将主体包含在“PUT”请求中。如果您需要'application/x-www-form-urlencoded'类型的主体,那么您应该(在ColdFusion中)使用本答案中描述的技术。 – yfeldblum 2010-10-20 18:25:19