【问题标题】:Connect to remote API using ColdFusion cfhttp使用 ColdFusion cfhttp 连接到远程 API
【发布时间】:2017-08-30 14:40:57
【问题描述】:

我正在尝试使用 ColdFusion 连接到 emma api。使用下面的代码。 Trying to get a listing of all members in an account 根据 api 文档执行以下操作。在下面的调用中,我不断收到 404 的状态代码。关于我在这里缺少什么的任何想法?

<cfset account_id= '123'/>
<cfset public_key = 'abc'/>
<cfset private_key = 'xyz' /> 
<cfset the_url = 'https://app.e2ma.net/#account_id#/members/' />

<cfhttp url="#the_url#" method="get" result="Results" timeout="999">
      <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
      <cfhttpparam type="header" name="Accept" value="application/json"  />
      <cfhttpparam type="header" name="public_api_key" value="#public_key#" >
      <cfhttpparam type="header" name="private_api_key" value="#private_key#" >
</cfhttp>
<cfdump var="#Results#"/> 

这是cfdump的结果:

【问题讨论】:

  • 在成员上不带斜线试试。还要确保您使用的 account_id 有效。他们的文档与他们如何使用 # 有点混淆,因为它在 URL 中有效,但是您尝试发出的请求显示时没有尾部斜杠 (GET /#account_id/members)
  • 试过没有斜杠,还是一样。我也认为我有正确的网址
  • 我认为公共和私有 api 密钥需要作为标头而不是表单字段发送。 helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/…
  • 如果你看看他们的主页,他们有一些例子。这是 PHP 但是,他们使用api.e2ma.net 而不是app.e2ma.net。这是他们的例子:$url = "https://api.e2ma.net/".$account_id."/members/add";.
  • 是的,大声笑,使用正确的网址肯定会有所帮助。乍一看,我错过了。现在您应该可以使用标头进行基本身份验证了

标签: json coldfusion cfhttp


【解决方案1】:

您似乎使用了错误的端点。在他们的documentation 中,他们说:

我们所有 API 调用的端点是https://api.e2ma.net/

在您使用app.e2ma.net 的代码中,这应该是api.e2ma.net

此外,您请求的 URL 的路径在他们的文档中不包含尾部斜杠(GET /#account_id/members 是他们所拥有的)。您可能还想更新它。

【讨论】:

  • 我的投票让你的声望超过 1000。你欠我一杯啤酒。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-19
  • 1970-01-01
  • 1970-01-01
  • 2014-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多