私のVertx ServerはサーバーAにあり、クライアントはサーバーBにあります。私がvertxサーバーにアクセスしようとすると、CORSエラーが表示されます。CORS問題を処理するサーバー側のコードを追加しました。ワーキング。クライアント側にヘッダを追加する必要がありますか?私はここで何が欠けていますか?私はheader.Now私のコードでwithCredential属性がvertexでのCORSの問題アプリケーションが動作しない
のように見える削除:
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.route().handler(io.vertx.rxjava.ext.web.handler.CorsHandler.create("*")
.allowedMethod(io.vertx.core.http.HttpMethod.GET)
.allowedMethod(io.vertx.core.http.HttpMethod.POST)
.allowedMethod(io.vertx.core.http.HttpMethod.OPTIONS)
.allowedHeader("Access-Control-Request-Method")
.allowedHeader("Access-Control-Allow-Credentials")
.allowedHeader("Access-Control-Allow-Origin")
.allowedHeader("Access-Control-Allow-Headers")
.allowedHeader("Content-Type"));
クライアントの実装:
function(url, user) {
eventBus = new EventBus(url);
eventBus.onopen = function() {
//Do Something
}
}
を更新誰もが
VERTXサーバーサイドのを助けることができます
if (ar.succeeded()) {
routingContext.response().setStatusCode(200).setStatusMessage("OK")
.putHeader("content-type", "application/json")
.putHeader("Access-Control-Allow-Origin", "*")
.putHeader("Access-Control-Allow-Methods","GET, POST, OPTIONS")
.end(
Json.encodePrettily(ar.result().body())
//(String) ar.result().body()
);
routingContext.response().close();
まだ次のエラーが表示されます。手伝ってくれますか?
XMLHttpRequest cannot load https://192.168.1.20:7070/Notify/571/rn4nh0r4/xhr_send?t=1471592391921. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'https://login.com' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.
アップデート2:
.putHeader("Access-Control-Allow-Origin", "*")
で私のクライアントのアドレスを追加した後、私は次しまったログ:
XMLHttpRequest cannot LOAD https://192.168.1.20:7070/Notify/773/k3zq1z2z/xhr_send?t=1471601521206. Credentials flag IS 'true', but the 'Access-Control-Allow-Credentials' header IS ''. It must be 'true' TO allow credentials. Origin 'https://login.com' IS therefore NOT allowed access.
次のように私のコードは次のとおりです。
if (ar.succeeded()) {
routingContext.response().setStatusCode(200).setStatusMessage("OK")
.putHeader("content-type", "application/json")
.putHeader("Access-Control-Allow-Origin", "https://login.com")
.putHeader("Access-Control-Allow-Methods","GET, POST, OPTIONS")
.putHeader("Access-Control-Allow-Credentials", "true")
.end(
Json.encodePrettily(ar.result().body())
//(String) ar.result().body()
);
routingContext.response().close();
に設定されたあなたはhttp://stackoverflow.com/questions/33124625/how-to-を見たことがありますが、次のように私のコードがありますx-2-x質問を有効にする? –
@カロール私は試しましたが、エラーを投げます。 失敗:WebSocketハンドシェイク中にエラーが発生しました:予期しない応答コード:400 –
WebSocketはこのHTTP要求と関係がありますか? :) –