简体   繁体   English

无法在node.js上获取angularjs http请求消息数据

[英]Cannot get angularjs http request message data at node.js

The client side code snippet: 客户端代码段:

$http({
  method: 'GET',
  url: '/admin?operation=getAdminInfo',
  data: {data: 'test'}
}).then(function(rsp){...});

The server side code snippet: 服务器端代码段:

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));

The output in the server console: 服务器控制台中的输出:

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

How can I extract/get the data {data: 'test'} at node.js? 如何在node.js中提取/获取数据{data: 'test'} AngularJS version is 1.6.6; AngularJS版本是1.6.6; Node.js version is v8.1.4; Node.js版本为v8.1.4; app.js at node.js: enter link description here node.js上的app.js: 在此处输入链接描述

Change the method from Get to Post, since you are sending an object to the server. 因为要将对象发送到服务器,所以将方法从“获取”更改为“发布”。

$http({
  method: 'POST',
  url: '/admin?operation=getAdminInfo',
  data: {data: 'test'}
}).then(function(rsp){...});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM