使用使用ColdFusion

时间:2016-04-27 15:01:08

标签: json api soap coldfusion

我获得了一个URL,该URL应该返回一些JSON数据,其中包含一个oAuth Token来访问其余的API。 API调用使用GET,它包含URL中的用户名和密码。

当我尝试访问API的网址时,我收到以下消息:

error   unauthorized
error_description   An Authentication object was not found in the SecurityContext

以下是我的ColdFusion示例:

<CFHTTP URL="https://test-ows01.website.com/data_api//1.0/oauth/token?grant_type=password&username=HelloWorld&password=MyPassword!" method="GET" result="result">
</CFHTTP>

<cfset content = deserializeJSON(result.filecontent.toString())>

<cfdump var="#content#">

其他信息:当我将URL(这个问题不是正确的URL)放入浏览器时,我会收到“登录”提示,输入用户名后:HelloWorld和密码:MyPassword!然后我进入一个页面,显示包含oAuth Token和其他数据的JSON数据。

我获得了一个SOAPUI文件,因此请查看API的工作原理,如果我需要提供其他信息,我可以从那里获取。

1 个答案:

答案 0 :(得分:2)

您要连接的服务器在请求期间需要身份验证凭据。将用户名和密码添加到cfhttp标记以在请求中发送凭据。

<cfhttp  url="example.com/data_api//1.0/oauth/token?grant_type=password" method="GET" result="result" 
    username="HelloWorld" password="MyPassword!">
</cfhttp>
相关问题