简体   繁体   English

角laravel nginx 400错误请求

[英]angular laravel nginx 400 Bad Request

Help, I've got 400 error on POST and or PUT method, but GET works just fine, I'm using angular as front end and laravel as API, my server is using nginx, I've used CORS and I everything works fine on my local vagrant which is running on apache. 帮忙,我在POST和/或PUT方法上遇到400错误,但是GET正常工作,我使用angular作为前端,使用laravel作为API,我的服务器使用nginx,我使用了CORS,而且一切正常在我正在本地运行的本地流浪汉上。

I'm sure I have my route set correctly, here's some of it from the module I use: 我确定我的路由设置正确,这是我使用的模块中的一部分:

 Route::group(array('prefix'=>'/api', 'middleware' => 'cors'),function(){
     Route::post('/create_level',      'LevelController@store');
     Route::get('/read_level',        'LevelController@index');
     Route::get('/read_level/{id}',    'LevelController@show');
     Route::put('/read_level/{id}', 'LevelController@update');
     Route::delete('/read_level/{id}', 'LevelController@destroy');

here's part of my angular service: 这是我的角度服务的一部分:

app.service("edulevelService", function ($http, $q, $rootScope)
{
 edu.updateEdulevel = function(id, edu){
            var deferred = $q.defer();
            $http.put($rootScope.endPoint + 'read_level/'+ id, edu)
            .success(function(res)
                {
                deferred.resolve(res);
                })
            .error(function(err, stat){
                deferred.reject(err);
                console.log('error code: Ser-UEDU');
                });         
                return deferred.promise;
        }

edu.createEdulevel = function(edu){
        var deferred = $q.defer();
        $http.post($rootScope.endPoint + 'create_level', edu)
        .success(function(res)
            {
            deferred.resolve(res);
            })
        .error(function(err, stat){
            deferred.reject(err);
            console.log('error code: Ser-CEDU');
            });
        return deferred.promise;        
    }
....

oh I forgot to mention different method cause different error code POST cause 405, PUT cause 400, and I've tried using Postman: POST is working using text type and return 405 using application/json, but when I tried PUT method even though it return 200 I only got NULL data entered to my db (text type), and if I use application/json it return 400 哦,我忘了提及不同的方法,导致不同的错误代码POST导致405,PUT引起400,并且我尝试使用Postman:POST正在使用文本类型工作,并使用application / json返回405,但是当我尝试PUT方法时,即使它返回200我仅将NULL数据输入到我的数据库(文本类型),如果我使用application / json,则返回400

Please Help 请帮忙

Finally found solution: change $http.post to: 终于找到解决方法:将$ http.post更改为:

 $http({ method: "post", url: $rootScope.endPoint + 'create_level', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: $.param({ .... }) }) 

somehow it works, exept on my login page which using stellizer to do post method and i can't find how should I change it without breaking all the function... 它以某种方式工作,在我的登录页面上显示出来,该页面使用stellizer进行发布方法,我找不到如何更改它而不破坏所有功能...

any one? 任何人? I only need to add: headers: {'Content-Type': 'application/x-www-form-urlencoded'} and data: $.param({ ...... }) 我只需要添加:标头:{'Content-Type':'application / x-www-form-urlencoded'}和数据:$ .param({......})

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

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