鍍金池/ 問答/HTML/ NODEJS上 post 一個https請求 ,返回401,請問是什么問題?

NODEJS上 post 一個https請求 ,返回401,請問是什么問題?

現(xiàn)象 NODEJS上 post 一個https請求 ,返回401,請問是什么問題?
在postman 等工具驗證了 , 用戶名口令,網(wǎng)址接口沒有問題。
同時,如果改username 為其他的參數(shù),會返回401.我懷疑是post_data格式問題。

歡迎任何建議和幫助

代碼

const https = require('https');
var username='11111';
var password='11111';
 

 
var post_data = JSON.stringify({'username' : username,'password' : password});
 
 
console.log('post_data:',post_data,post_data.length);
var headers = {
   //'Content-Type' : 'application/x-www-form-urlencoded',
   'Content-Type' : 'Application/json',
   'Content-Length' : post_data.length             
   };
   
const options = {
  hostname: 'cas.testtest.com',
  port: 443,
  path: '/vtest/user/login',
  method: 'POST',
  headers: headers,
  
};

const req = https.request(options, function(res){
  console.log('statusCode:', res.statusCode);
  //console.log('headers:', res.headers);
    
  res.on('data', function(d){
     process.stdout.write(d);
  });
});
req.on('response', function (response) {
    console.log('response:',response);
} );
req.on('error', function(e){
  console.error('[https]:',e);
});
req.write(post_data);
 

req.end(); 
回答
編輯回答
雅痞

401 授權(quán)失敗,,百度下就知道了,登錄信息有問題

2017年11月3日 20:54
編輯回答
眼雜

遇到同樣的問題,我這是開發(fā)Web項目的時候使用JWT認證,接受token時,后端直接返回401,不知道什么情況,賬戶名和密碼使用POST提交

2017年4月5日 14:14