簡體   English   中英

Laravel服務-無法發布

[英]Laravel serve - can't post

我正在嘗試構建API,wamp的OAuth出現問題,因此我正在使用Laravel Serve。 我使用Laravel 5.3護照,每次我POST ,響應是空白,沒有響應正確的頭(Access-Control-Allow-Origin) 它也只需要9MS就能獲得響應(應該更長一些,使用PUT接近9MS )。 但是,如果我使用PUT ,它將正常工作。

VUE:

Vue.http.headers.common['Accept'] = 'application/json';
Vue.http.headers.common['Authorization'] = 'Bearer ' + token;

this.$http.post('http://127.0.0.1:8000/api/post/' + this.post.id + '/comment', formData)
            .then(response => {
                console.log(response);
            }, response => {
                // error
            });

中間件:

protected $middleware = [
   \Barryvdh\Cors\HandleCors::class,
];

protected $middlewareGroups = [
   'api' => [
        'throttle:60,1',
        'bindings',
   ],
]

路線:

Route::group(['middleware' => 'auth:api'], function() {
    // 
    Route::post('/post/{id}/comment, 'Api\Post\CommentController@add');
});

控制器:

public function add(Request $request, $post_id)
{
   // 
   return response()->json(['status' => 'success'], 200);
}

花很多時間在應該起作用的東西上-有什么想法嗎?

謝謝

好的,所以我終於弄清楚了什么地方出了問題。 我正在查看Laravel日志而不是PHP日志。 (Do!)

我得到的錯誤:

推薦使用PHP:不建議自動填充$ HTTP_RAW_POST_DATA,並且在以后的版本中將其刪除。 為避免此警告,請在php.ini中將“ always_populate_raw_post_data”設置為“ -1”,並改用php:// input流。 在第0行的Unknown中

解決方案也是將always_populate_raw_post_data=-1添加到我的php.ini文件中:

C:\wamp64\bin\php\php7.1.9
C:\wamp64\bin\php\php7.0.23
C:\wamp64\bin\php\php5.6.31
C:\wamp64\bin\apache\apache2.4.27\bin

重新啟動WAMP服務

暫無
暫無

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

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