Meteor HTTP.post 不适用于 Trello API [英] Meteor HTTP.post not working with Trello API
问题描述
我正在尝试使用 Meteor 的 HTTP.post 方法通过 Trello API 创建一个 webhook,如下所示:
I'm trying to create a webhook through the Trello API by using Meteor's HTTP.post method like this:
HTTP.post('https://api.trello.com/1/webhooks?key=...&token=...', {
params: {
idModel: '...',
callbackURL: '...'
},
}, function(error, result) {...});
请求有效,但我得到的响应是idModel 的值无效".但是,如果我使用 jQuery 尝试相同的请求:
The request works but the response i get is "Invalid value for idModel". However, if i try the same request using jQuery:
$.ajax({
type: 'POST',
url: https://api.trello.com/1/webhooks?key=...&token=...,
data: {
idModel: '...',
callbackURL: '...'
},
});
一切正常(即创建了 webhook 并返回了数据).不知何故,Meteor 的方法似乎使 Trello 无法解析 idModel 字段.任何想法这背后可能是什么?我做错了什么还是有错误?
Everything works fine (i.e. the webhook is created and data is returned). Somehow Meteor's method seems to make it impossible for Trello to parse the idModel field. Any ideas what might be behind this? Am i doing something wrong or is there a bug?
推荐答案
我通过将 Content-Type
标头设置为 application/x-www-form-urlencoded
.它之前是作为 text/plain
发送的.
I solved it by setting the Content-Type
header to application/x-www-form-urlencoded
. It was sent as text/plain
before.
HTTP.post('https://api.trello.com/1/webhooks?key=...&token=...', {
params: {
idModel: '...',
callbackURL: '...'
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}, function(error, result) {...});
这篇关于Meteor HTTP.post 不适用于 Trello API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!