【发布时间】:2018-01-15 22:23:26
【问题描述】:
我正在尝试向 Githubs graphql api(v4) 发送一个 http 请求。我的猜测是我的查询格式错误。下面的代码用于向 api 发送 POST 请求。
app.get('/fetch-data', function(req, res, next) {
const access_token = settings.dev.TOKEN;
const query = {query: { viewer: { 'login': 'muckbuck' } }};
const options = {
uri: 'https://api.github.com/graphql',
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': "Bearer " + access_token,
'User-Agent': 'request',
'contentType': "application/graphql",
},
data: query
};
function callback(error, response, body) {
console.log(response.body)
if (!error && response.statusCode == 200) {
console.log(body);
console.log('lol');
}
}
request(options, callback);
});
我得到的错误信息:
{"message":"Problems parsing JSON","documentation_url":"https://developer.github.com/v3"}
【问题讨论】:
-
确定“contentType”?那不应该是“内容类型”吗???
-
是的,我认为你是对的,但遗憾的是它并没有解决问题。
标签: json node.js http github graphql