Javascript 邮递员和angularjs服务中的不同响应

Javascript 邮递员和angularjs服务中的不同响应,javascript,angularjs,api,http,Javascript,Angularjs,Api,Http,所以当我从邮递员那里调用endpoint时,我得到如下响应: 当我从angularjs服务调用相同的请求时: this.login = function (loginInfo) { return $http({ url: 'http://localhost/igt/api/public/signin', headers: { 'Content-Type': 'Application/json' },

所以当我从邮递员那里调用endpoint时,我得到如下响应:

当我从angularjs服务调用相同的请求时:

this.login = function (loginInfo) {

    return $http({
        url: 'http://localhost/igt/api/public/signin',
        headers: {
            'Content-Type': 'Application/json'
        },
        method: 'POST',
        user: {
            name: "nick",
            password: "password"
        }
    })
    .then(function(response) {
        console.log(response);
    }, function (err) {
        console.log("err:");
        console.log(err);
    });
};
控制台中的输出如下所示:

这是什么

{
  "data": null,
  "status": 400,
  "config": {
    "method": "POST",
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "jsonpCallbackParam": "callback",
    "url": "http://localhost/igt/api/public/signin",
    "headers": {
      "Accept": "application/json, text/plain, */*"
    },
    "user": {
      "name": "nick",
      "password": "password"
    }
  },
  "statusText": "Bad Request",
  "xhrStatus": "complete"
}

为什么会有这种差异?

以下是配置对象属性,请按此设置您的http配置

method – {string} – HTTP method (e.g. 'GET', 'POST', etc)
url – {string|TrustedObject}
params – {Object.<string|Object>
data – {string|Object}
headers – {Object}
eventHandlers - {Object}
uploadEventHandlers - {Object}
xsrfHeaderName – {string}
xsrfCookieName – {string}
transformRequest – {function(data, headersGetter)|Array.<function(data, headersGetter)>} – 
transformResponse –
paramSerializer
cache 
timeout
withCredentials - {boolean}
responseType - {string}

从你的邮递员输入应该是

{
 user:{
 name:"",
password:""
}
}
但是你要发送的是

{
    name:"",
    password:""
    }
改变你的js代码如下

user: {
   user : {
name:"nick",
password:"password"
}
}
它会起作用的

同时将标题更改为 “内容类型”:“应用程序/json” 从…起
“内容类型”:“应用程序/json”

我不是AngularJS方面的专家,但这不应该是
方法:'POST',数据:{user:{…}}
?是的,应该是,但它告诉我我没有通过有效的json。。。
user: {
   user : {
name:"nick",
password:"password"
}
}