AngularJS Post不工作

问题描述 投票:0回答:1

这是一个在提交表单然后将数据提交给api后执行的函数,所有这些都是使用$ http服务以1.5角度完成的

我用postman来测试这些方法(GET,DELETE,POST)和其他方法,它们都运行良好。在我的应用程序虽然POST由于某种原因似乎注意工作,即使在邮递员我遵循相同的结构。

我得到的错误是名称是一个要求,我相信是API确保输入信息。

我似乎无法理解为什么这在post post中工作得很好但不在我的角度应用中。任何帮助将不胜感激。

 function createDocument(newMovie){


            var req = {
                method: 'POST',
                url:{{some url}},
                headers: 
                      { 
                        "Authorization": Authorization,
                        "content-type": "application/json"
                      },
                body: { 
                        "name": newMovie.name, 
                        "description": newMovie.description, 
                        "imgs":[
                           {
                             "url": newMovie.imgs
                           }
                        ]
                      }
             }  


            $http(req)
                .success(function(response){
                    console.log('success', response);
                })
                .error(function(response){
                    console.log('error', response);
                })
                ;
        }
angularjs post angularjs-http
1个回答
1
投票

它应该是数据,而不是身体。

data: { 
                        "name": newMovie.name, 
                        "description": newMovie.description, 
                        "imgs":[
                           {
                             "url": newMovie.imgs
                           }
                        ]
                      }
© www.soinside.com 2019 - 2024. All rights reserved.