簡體   English   中英

角laravel nginx 400錯誤請求

[英]angular laravel nginx 400 Bad Request

幫忙,我在POST和/或PUT方法上遇到400錯誤,但是GET正常工作,我使用angular作為前端,使用laravel作為API,我的服務器使用nginx,我使用了CORS,而且一切正常在我正在本地運行的本地流浪漢上。

我確定我的路由設置正確,這是我使用的模塊中的一部分:

 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');

這是我的角度服務的一部分:

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;        
    }
....

哦,我忘了提及不同的方法,導致不同的錯誤代碼POST導致405,PUT引起400,並且我嘗試使用Postman:POST正在使用文本類型工作,並使用application / json返回405,但是當我嘗試PUT方法時,即使它返回200我僅將NULL數據輸入到我的數據庫(文本類型),如果我使用application / json,則返回400

請幫忙

終於找到解決方法:將$ http.post更改為:

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

它以某種方式工作,在我的登錄頁面上顯示出來,該頁面使用stellizer進行發布方法,我找不到如何更改它而不破壞所有功能...

任何人? 我只需要添加:標頭:{'Content-Type':'application / x-www-form-urlencoded'}和數據:$ .param({......})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM