使用 Coldfusion/Railo 向 Mailchimp API v3.0 发送 PUT 请求时出现 401 未经授权的错误
Posted
技术标签:
【中文标题】使用 Coldfusion/Railo 向 Mailchimp API v3.0 发送 PUT 请求时出现 401 未经授权的错误【英文标题】:401 Unauthorized error when sending PUT request to Mailchimp API v3.0 using Coldfusion/Railo 【发布时间】:2016-05-19 13:02:16 【问题描述】:我正在为 Mailchimp 的 restful Services V3.0 创建一个 Coldfusion/Railo API 包装器。 GET 请求工作正常,但我在将数据放入 Mailchimp 时遇到问题。
我的代码格式是:
httpService.setMethod("PUT") ;
httpService.setURL("https://us12.api.mailchimp.com/3.0/lists/d9****81/members/e311cfde*****************2dda77c0") ;
httpService.addParam(type="URL",name="apikey", value="*******************-us12");
httpService.addParam(type="URL",name="user", value="jnicola2:******************-us12");
httpService.addParam(type="BODY",name="status", value="Subscribed") ;
httpService.addParam(type="BODY",name="email_address", value="*****@*****.co.uk") ;
httpService.addParam(type="BODY",name="interests", value=""ae4****7e5":true,"675****75a":true,"1ab****7f":false,"cf0****8ef":true,"38be****2a":false") ;
响应错误 错误详细信息:401 未经授权 filecontent: "type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"API Key Missing","status":401,"detail":"您的请求不包含 API 密钥。","instance":" "
我的电话有什么问题?
【问题讨论】:
【参考方案1】:您必须将 apikey 放在 Authorization 标头中,请参见此示例:
var requestBody = "email_address"="*****@*****.co.uk", "status"="subscribed";
httpService = new
http(url="https://us12.api.mailchimp.com/3.0/lists/d9****81/members",method="POST",timeout=3);
httpService.addParam(type="header", name="Content-Type", value="application/json");
httpService.addParam(type="header",name="Authorization", value="apikey *******************-us12");
response = httpService.send().getPrefix();
dump(response)
【讨论】:
以上是关于使用 Coldfusion/Railo 向 Mailchimp API v3.0 发送 PUT 请求时出现 401 未经授权的错误的主要内容,如果未能解决你的问题,请参考以下文章