0
superagent
でpost
リクエストを作成しようとしていますが、常に失敗します。私は複数のヘッダーを追加するなど、インターネットから多くのソリューションを試しましたが、どれもうまくいかないようです。コード:Reactでのスーパーエージェントによる投稿要求が失敗しました
createUser() {
var email = this.refs.email.value;
Request.post('http://advacedcrm.local/api/users/create').set('Accept', 'application/json').send({email: email}).then((response) => {
console.log(response);
});
}
私はAPIはまた私によって作られていることに言及しなければならない、と私はそこにいくつかのヘッダーを置く:
header('Access-Control-Allow-Origin: http://localhost:3000');
をroutes.php
ファイルの先頭に(Laravel 5.2
に)。 APIミドルウェア:
public function handle($request, Closure $next)
{
if ($request->isMethod('options')) {
return response('', 200)
->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
->header('Access-Control-Allow-Headers', 'accept, content-type, x-xsrf-token, x-csrf-token');
}
return $next($request);
}
しかし、私はそれを投稿したときに、エラーが私が受けている:
XMLHttpRequest cannot load http://advacedcrm.local/api/users/create. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
は、だから私はアイデアの出だが、何が間違っているのですか?