【发布时间】:2018-05-17 06:23:22
【问题描述】:
我正在尝试构建 API,但 wamp 遇到了 OAuth 问题,所以我使用 Laravel Serve。我正在使用Laravel 5.3 Passport,每次我POST,响应都是空白的,并且没有响应正确的标题(Access-Control-Allow-Origin)。它也只需要9MS 来获得响应(应该更长,PUT 接近 600MS)。但是,如果我使用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);
}
花费大量时间在应该可行的事情上 - 有什么想法吗?
谢谢
【问题讨论】:
-
我还应该提到,对于 WAMP,请求始终是
Unauthenticated(GET、POST、PUT、DELETE)。这就是我不使用 WAMP 的原因 - 关于它删除标题的一些事情。
标签: php laravel oauth wamp passport.js