SurveyMonkey api Coldfusion issue



我在使用 cfhttp 和 cfhttpparam 让标头参数"授权"正常工作时遇到问题。

连接工作正常...我正在通过我们的代理出去,所以这不是问题。

API 文档指出,标头中的"授权"应格式化为"授权:持有者 XXXYYYZZ"。

当我尝试添加带有空格的"持有者"时,出现以下错误:{"status":3,"errmsg":"预期的对象或值"}

当我根本不添加前缀"持有者"时,出现以下错误:{"status":1,"errmsg":"请求标头中的"授权"数据无效"}

我也尝试了"承载者XXXYYYZZ"和"承载者

%20XXXYYYZZ"和"承载 者XXXYYYZZ",结果相同。

有什么想法吗?谢谢!

法典:

<cfhttp 
    timeout="2000" 
    url="https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxxx"
    proxyserver="proxy.xxxx.com" 
    proxyport="8080" 
    method="post" 
    result="httpResponse" 
    charset="utf-8"
    throwonerror="Yes">
    <cfhttpparam type="header" name="Authorization" value="bearer XXXYYYZZ">
</cfhttp>
<cfdump var="#httpResponse#">

响应:

字符集 UTF-8
错误详细信息 [空字符串]
文件内容 {"status":1,"errmsg":"请求标头中的"授权"数据无效"}
标头 HTTP/1.1 200 OK 访问控制暴露标头:缓存控制,内容语言,内容类型,过期,上次修改时间,编译指示,日期,内容长度内容类型:应用程序/json;字符集=UTF-8 日期:2016 年 1 月 28 日星期四 13:16:11 GMT 服务器:nginx/1.4.6 (Ubuntu) SM-请求 ID:251952a7-9d21-470e-807d-9b48adf0892b X-Mashery-消息 ID:9ebad058-e4e5-4cc9-b9cf-bf33dee9fbc6 X-Mashery-响应者:prod-j-worker-us-west-1b-58.mashery.com X 计划-QPS 分配:6 X 计划-QPS 当前:1 X 计划配额分配:7000 X 计划配额当前:5 X 计划配额重置:2016 年 1 月 29 日星期五上午 12:00:00 GMT 内容长度:72 连接:关闭
Mimetype application/json
响应标头

结构

访问控制暴露标头缓存控制,内容语言,内容类型,过期,上次修改时间,杂注,日期,内容长度
连接关闭
内容长度 72
内容类型应用程序/json;字符集=UTF-8
日期 星期四, 28 一月 2016 13:16:11 GMT
解释确定
Http_Version HTTP/1.1
SM-请求编号 251952a7-9d21-470e-807d-9b48adf0892b
服务器 nginx/1.4.6 (Ubuntu)
Status_Code 200
X-Mashery-Message-ID 9ebad058-e4e5-4cc9-b9cf-bf33dee9fbc6
X-Mashery-Responder prod-j-worker-us-west-1b-58.mashery.com
X计划-QPS分配6
X-计划-QPS-电流 1
X计划配额分配7000
X 计划配额当前 5
X计划配额重置 2016年1月29日星期五上午12:00:00 GMT

状态代码 200 正常
文本是

看起来您需要在正文中发送一个空的 JSON 结构。API 需要 JSON 输入,即使没有要发送的参数也是如此。只需添加另一个值为 {}body 类型的cfhttpparam

<cfhttp 
    timeout="2000" 
    url="https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxxx"
    proxyserver="proxy.xxxx.com" 
    proxyport="8080" 
    method="post" 
    result="httpResponse" 
    charset="utf-8"
    throwonerror="Yes">
    <cfhttpparam type="header" name="Authorization" value="bearer XXXYYYZZ">
    <cfhttpparam name="body" type="body" value="{}">
</cfhttp>
<cfdump var="#httpResponse#">
<cfhttp 
    timeout="2000" 
    url="https://api.surveymonkey.net/v2/surveys/get_survey_list/?api_key=xxxx"
    proxyserver="proxy.xxxx.com" 
    proxyport="8080" 
    method="post" 
    result="httpResponse" 
    charset="utf-8"
    throwonerror="Yes">
    <cfhttpparam type="header" name="Authorization" value="bearer XXXYYYZZ">
    <cfhttpparam type="header" name="Content-Type" value="application/json" />
    <cfhttpparam name="body" type="body" value="{}">
</cfhttp>
<cfdump var="#httpResponse#">

最新更新