angularjs $http.post报错 415

           $http({
                url: 'http://54.238.128.198:8081/user/register',
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                data: {
                    'userName': $scope.myName,
                    'password': $scope.myPwd
                }
            }).then(function(data) {
                console.log(data);
            }, function(xhr) {
                console.log('请求失败');
            });

图片描述

跨域是没有问题,现在是415错误?

阅读 3.2k
2 个回答

你设置了header'Content-Type': 'application/x-www-form-urlencoded'
这是form表单提交格式'userName'='aaa'&'password'='bbb'
但你用的是json格式
你看看是不是这个问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题