Мой сервер Vertx находится на сервере A и клиент находится на сервере B. Когда я пытался получить доступ к серверу vertx, появляется ошибка CORS. Я добавил код на стороне сервера для обработки проблемы CORS, но это не за работой. Нужно ли добавлять заголовок на стороне клиента. что мне здесь не хватает? Может кто-нибудь помочьПроблема с CORS в vertx Приложение не работает
VertX стороны сервера: осуществление
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
}
}
Update:
Я удалил withCredential атрибута в header.Now моего кода выглядит
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.
Update2: После добавления моего клиента адрес в
.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- вопрос включения-корса-с-vert-x-2-x? –
@ Karol Я пробовал, но это порождает ошибку. не удалось: ошибка при рукопожатии WebSocket: неожиданный код ответа: 400 –
Что такое WebSocket для этих HTTP-запросов? :) –