Marc Plano-Lesay
09/02/2022, 9:53 AMinstall(CORS) {
anyHost()
}
A GET
request works just fine, but a POST
doesn't. Trying to be a bit more explicit with this:
install(CORS) {
anyHost()
allowHeader(HttpHeaders.ContentType)
allowMethod(HttpMethod.Get)
allowMethod(<http://HttpMethod.Post|HttpMethod.Post>)
}
results in the GET
not working either now. What's the minimum to get both GET
and POST
working from any host?Aleksei Tirman [JB]
09/02/2022, 11:03 AMAccess-Control-Allow-Origin: *
header:
curl -v -X POST --header 'origin: <http://localhost:3333>' <http://127.0.0.1:3333/>
Aleksei Tirman [JB]
09/02/2022, 11:04 AMembeddedServer(Netty, port = 3333) {
install(CORS) {
anyHost()
allowHeader(HttpHeaders.ContentType)
allowMethod(HttpMethod.Get)
allowMethod(<http://HttpMethod.Post|HttpMethod.Post>)
}
routing {
get("/") {
call.respondText { "get" }
}
post("/") {
call.respondText { "post" }
}
}
}.start(wait = true)
Marc Plano-Lesay
09/02/2022, 11:04 AMAleksei Tirman [JB]
09/02/2022, 11:05 AMMarc Plano-Lesay
09/02/2022, 11:06 AMAleksei Tirman [JB]
09/02/2022, 11:08 AMembeddedServer(Netty, port = 3333, host = "0.0.0.0") { // ...
Curl:
curl -v -X POST --header 'origin: <http://localhost:3333>' <http://0.0.0.0:3333/>
Response headers:
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Length: 4
< Content-Type: text/plain; charset=UTF-8
Marc Plano-Lesay
09/02/2022, 11:09 AMMarc Plano-Lesay
09/02/2022, 11:50 AMallowHeader(HttpHeaders.ContentType)
the first time I tried, but I have no idea why it didn't work when I tried with it just before posting here - now it works fine with that. Sorry for the trouble...