客户端代码段:
$http({
method: 'GET',
url: '/admin?operation=getAdminInfo',
data: {data: 'test'}
}).then(function(rsp){...});
服务器端代码段:
console.log('req = ' + req);
console.log('req.header = ' + JSON.stringify(req.header));
console.log('req.query = ' + JSON.stringify(req.query));
console.log('req.body = ' + JSON.stringify(req.body));
console.log('req.cookies = ' + JSON.stringify(req.cookies));
console.log('req.params = ' + JSON.stringify(req.params));
console.log('req.xhr = ' + JSON.stringify(req.xhr));
服务器控制台中的输出:
req = [object Object]
req.header = undefined
req.query = {"operation":"getAdminInfo"}
req.body = {}
req.cookies = {"token":"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzeXN0ZW0iLCJpc3MiOiJodHRwczovL3d3dy5uZXRhb3RlYy5jb20iLCJpYXQiOjE1MTYwNjM1Njk1MDQsInVzZXJfcm9sZSI6MSwidXNlcm5hbWUiOiJzeXN0ZW0iLCJleHAiOjE1MTYwNjM1NzY3MDR9.K2Rh4WTNtkhP2gxWLnGW7846zMKaW-WKEF2hykJmvn3zNmGyIDprrnswzqqrpmAvNTP8gylnCn3b7K_gRJ-WOif7MnQYiG4mu8fNGW-hCUQeTyqzUgsP9sIXzm_A3pWFlW8eL88Dydugf9JhhDeB18QUJV-i4zT6bCfE3stY1QXJZzNsKd8HRl22n78XCb5XRxdiEnmhqF6sNb9h40jKzcd6Ny0KX6uEe1SE54OYbp_BcR4Lr69C6tcFNgwtiJusFEymnMcbkqSst_GUztiObPeYZIwrfEUMEobUsxvx0v2zUQp9EJDF-MyaGid5kJwyv_ittFFKRChBSllI3luNXA"}
req.params = {}
req.xhr = false
如何在node.js中提取/获取数据{data: 'test'}
? AngularJS版本是1.6.6; Node.js版本是v8.1.4; node.js上的app.js:enter link description here
答案 0 :(得分:1)
将方法从Get更改为Post,因为您要将对象发送到服务器。
$http({
method: 'POST',
url: '/admin?operation=getAdminInfo',
data: {data: 'test'}
}).then(function(rsp){...});