开发者社区> 问答> 正文

angularjs的Post提交JSON格式数据报403错误,求助?报错

问题: 

客户端采用Ionic开发(基于angularjs)的应用,服务器端采用spring4的restful方式,使用get方式操作没有问题,数据返回json也没有问题,当客户端采用post方式时,在chrom浏览器方式调试也正常,即服务器可以得到提交的json数据并正确转换,但在手机设备上运行时报错,报403错误 (POST http://192.168.1.1:8080/MAP/api/v1/auth/signin 403 (Forbidden))服务器端无任何信息。

服务器端运行环境为:tomact7

客户端代码:
var login = function(username, password) {
            var user={'username': username ,'password':password};
            var url=config.ApiBaseUrl +'/auth/signin';
            return $http.post(config.ApiBaseUrl +'auth/signin',user,{'Content-Type':'application/json'})
                .then(
                function (response) {
                    console.log('login user='+response.data.content.account);
                    var AuthCode =response.data.code;
                    if('100'==AuthCode){
                        $user = response.data.content;
                        storeUserCredentials($user);
                        console.log('Login success.');
                    }
                    return AuthCode;
                },
                function (httpError) {
                    console.log('httpError='+JSON.stringify(httpError));                    return AuthCode;
                }
            );
        }


服务端代码:
    @RequestMapping(value="/signin",method = RequestMethod.POST,consumes = "application/json")
    public ResponseEntity<ResultModel> login(@RequestBody Account login) {
    String username=login.getUsername();
    String password=login.getPassword();
        Assert.notNull(username, "username can not be empty");
        Assert.notNull(password, "password can not be empty");

 //省略其他代码


展开
收起
爱吃鱼的程序员 2020-06-10 10:15:33 1011 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    应该是CORS没有处理好的问题,检查一下响应首部。

    2020-06-10 10:15:49
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载