私はサーバーアプリケーションにcodeigniter REST APIを使用しています。そしてAngular2のクライアントは、私のREST APIに基本認証を与えました。 、私は、角2 Requestヘッダーフィールド許可は、プリフライト応答でAccess-Control-Allow-Headersで許可されていません。
$config['rest_auth'] = 'basic';
そして
$config['rest_valid_logins'] = ['uname' => 'pwd'];
もCORSが、私はコードの下に使用しているチェックのためのよう
$config['check_cors'] = TRUE;
$config['allowed_cors_headers'] = [
'Origin',
'X-Requested-With',
'Content-Type',
'Accept',
'Access-Control-Request-Method'
];
$config['allowed_cors_methods'] = [
'GET',
'POST',
'OPTIONS',
'PUT',
'PATCH',
'DELETE'
];
$config['allow_any_cors_domain'] = TRUE;
を設定しているし、また、私は明示的に私の残りのコントローラでと試みた試してみました
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
コード:
私は郵便配達員と確認しても何の問題もなくうまくいきます。角度誤差とのチェックは、のようになると
XMLHttpRequest cannot load http://localhost:97/sencogold/index.php/Adminaccount_api/login_adminuser. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
場合、私はfalse残りauthおよび
$config['rest_auth'] = FALSE;
APIのユーザー名とパスワードを確認することはせずにうまく機能しているAuthorizationヘッダを削除し、
角度でthis.headers = new Headers();
//this.headers.append('Authorization', 'Basic ' + btoa('lmxretail:[email protected]'));
this.headers.append('Content-Type', 'application/x-www-form-urlencoded');
私のAPIに認証を適用するのを手伝ってください。
チェック。ヘッダーは許可されるかどうか。 –
この問題を解決するためにChromeに「Access-Control-Allow-origin」プラグインを追加しますが、永続的な解決策ではありません。 –
[ドメイン間リクエスト(Angular 2)を作成するにはどうすればいいですか?](https://stackoverflow.com/questions/34790051/how-to-create-cross-domain-request-angular-2) – echonax