简体   繁体   English

angularjs 1.5 / laravel bad request 400

[英]angularjs 1.5 / laravel bad request 400

When I do a POST request using my angular app to my laravel api I get an error bad request 400 , however GET requests work normally, also I do POST requests using POSTMAN and it works , here is my code : 当我使用我的角度应用程序向我的laravel api发出POST请求时,我得到错误请求400,但是GET请求正常工作,我也使用POSTMAN进行POST请求并且它有效,这是我的代码:

$http.get('http://localhost/laravel/datingApp/jobapi/public/api/user/users');

this get request works, this post request doesn't (data is an js object {'email': 'value','password': 'value'}) : 此get请求有效,此post请求不起作用(数据是js对象{'email':'value','password':'value'}):

  $http({

            url: 'http://localhost/laravel/datingApp/jobapi/public/api/user/login',
            method: 'POST',
            contentType: "application/json",
            data: data

  }).success(function(data) {

            console.log(data);

  });

also I tried doing that just regular way: $http.post('blabla'); 我也尝试过常规方式: $http.post('blabla'); but it doesn't work either :( 但它也不起作用:(

edit: sorry didn't include error: 编辑:抱歉没有包含错误:

angular.js:12011 POST   
http://localhost/laravel/datingApp/jobapi/public/api/user/login 400 (Bad Request)

(anonymous function)          @ angular.js:12011
sendReq                       @ angular.js:11776
serverRequest                 @ angular.js:11571
processQueue                  @ angular.js:16383
(anonymous function)          @ angular.js:16399
$eval                         @ angular.js:17682
$digest                       @ angular.js:17495
$apply                        @ angular.js:17790
(anonymous function)          @ angular.js:25890
dispatch                      @ jquery.min.js:3
q.handle                      @ jquery.min.js:3

这是一个愚蠢的错误,但是由于@piscator我找到了它,Laravel默认返回400,当验证规则不满足时,所以我的输入一直是错误的,这就是我得到400的原因。

If the post request is working via postman, it seems that when your angular app does an post request it gets stuck due to browser CORS policy. 如果帖子请求通过邮递员工作,似乎当你的角度应用程序发出一个帖子请求时,它会因浏览器CORS策略而卡住。

You need to have a access-control-allow-origin present in the header of the response for the post requests to works. 您需要在响应的标头中提供access-control-allow-origin才能使post请求生效。

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

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