【发布时间】:2016-08-30 22:02:13
【问题描述】:
我正在尝试使用 ColdFusion CFHTTP 模拟以下 cURL 请求
curl -u myCl13nt1D:my53cR3tK3Y -X POST --data "grant_type=password&username=x&password=y" https://www.sitename.net/token
<cfhttp url="https://www.sitename.net/token" method="post" username="x" password="y">
<cfhttpparam type="url" name="client_id" value="myCl13nt1D" />
<cfhttpparam type="url" name="client_secret" value="my53cR3tK3Y" />
<!--- attempt 1 - without using cfhttp username/password attributes
<cfhttpparam type="formfield" name="grant_type" value="password" />
<cfhttpparam type="formfield" name="username" value="x" />
<cfhttpparam type="formfield" name="password" value="y" />
--->
<!--- attempt 2 - without using cfhttp username/password attributes
<cfhttpparam type="formField" name="data" value="grant_type=password&username=x&password=y" />
--->
<!--- attempt 3 - using cfhttp username/password attributes --->
<cfhttpparam type="formField" name="data" value="grant_type=password" />
</cfhttp>
在命令提示符下,cURL 请求可以返回预期结果,但使用 CFHTTP 我收到以下错误(状态代码 401 Unauthorized)
{"error":"unauthorized_client","error_description":"That application is not registred or blocked"}
我尝试了不同的方法来传递所需的参数,但它们都返回相同的错误。
【问题讨论】:
-
尝试将您的 CURL 按原样发布到 CF 页面并捕获请求的所有变量 - 然后看看您是否可以通过这种方式匹配它们。未知的可能是在标头中传递的用户名。该站点还可能需要不同的代理或其他任何东西......这很难说,但错误消息让我认为某些东西 - 一些令牌或其他东西 - 丢失了。
-
不应该是
username="myCl13nt1D" password="my53cR3tK3Y"in<cfhttp>吗?
标签: curl coldfusion cfhttp