2017-04-06 13 views
0

トークンとヘッダーを送信してAPIから応答を返そうとしていますが、私はしません私はどこに置くべきかを知っている。npmはトークンとヘッダー 'content-type'を同時に送信します: 'application/json'を同時に呼び出します

これは、これまでの私のコードです:

var request = require('request'); 

request.get('google example url', { 
// 
    'auth': { 
    'bearer': '15252727282' 
    }, 
    "headers": { 
    "Content-Type": "application/json" 
    } 
}, function (error, response, body) { 
    console.log('error:', error); // Print the error if one occurred 
    console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received 
    console.log('body:', body); 
}); 

は、これは私が戻って私のコンソールで取得していますものです:

error: null 
statusCode: 401 
body: HTTP Token: Access denied. 

答えて

0

あなたはどこにも必要と定義されたことがないので、あなたがそのエラーを取得していますあなたのクライアント側で。

プロジェクトにこれを追加します。http://requirejs.org/docs/release/2.2.0/minified/require.js

使用したい場合は、クライアント上で必要ではこのhttp://requirejs.org/を見てみましょう。私はそれが最初のパラメータとして、次の行でオプションを使用していた

0

OK:

const options = { 
 
    url: 'target url', 
 
    method: 'GET', 
 
    headers: { 
 
     "Authorization": "Token token=12425262", 
 
     "Content-type": "application/json" 
 
     
 
    } 
 
}; 
 

 
request(options, function(err, res, body) { 
 
    let json = JSON.parse(body); 
 
    console.log(json); 
 
});

関連する問題