curl - 将 cURL 请求命令转换为 Coldfusion (cfhttp)

标签 curl coldfusion cfhttp

我正在尝试使用 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 未经授权)

{"error":"unauthorized_client","error_description":"That application is not registred or blocked"}

我尝试了不同的方法来传递所需的参数,但它们都返回相同的错误。

最佳答案

-u myCl13nt1D:my53cR3tK3YBasicAuth并在 cfhttp 中拆分为 username/password 属性。试试这个:

<cfhttp url="https://www.sitename.net/token" method="post" username="myCl13nt1D" password="my53cR3tK3Y">
  <cfhttpparam type="formfield" name="grant_type" value="password" />
  <cfhttpparam type="formfield" name="username"   value="x"        />
  <cfhttpparam type="formfield" name="password"   value="y"        />
</cfhttp>

查看此请求,您已使用 BasicAuth 进行身份验证,并使用端点的用户名/密码登录机制进行授权,很可能 OAuth2 .

关于curl - 将 cURL 请求命令转换为 Coldfusion (cfhttp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39237768/

相关文章:

bash - Kubernetes cron作业循环调用curl

windows - 在所有图像/文件完成之前页面停止加载

jquery - 将表单从 jQuery 模式提交到 ColdFusion 操作页面

php - 将此 cuRL 转换为 CFHTTP - Azure NotificationHub

coldfusion - Nexmo API 和 CFHttp POST

php - 将 API 调用从 PHP 和 cURL 转换为 ColdFusion cfhttp

python - 企业防火墙背后的网络流量

php - 我想检查此 cURL 代码中的站点是否存在?

php - curl_multi_exec() : is not a valid cURL handle resource

coldfusion - 如何处理来自 ColdFusion 查询的空值?