Answer the question
In order to leave comments, you need to log in
CORS not passing PUT request?
I am accessing the server on jetty via fetch.
The response contains headers:
resp.addHeader("Access-Control-Allow-Origin", "*");
resp.addHeader("Access-Control-Allow-Methods", "PUT");
resp.addHeader("Access-Control-Allow-Headers", "Content-Type");
But the browser issues
Fetch API cannot load localhost:8081/admin/country. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' localhost:63343 ' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
With GET it works fine.
What is the reason for this strange behavior of the browser?
Answer the question
In order to leave comments, you need to log in
Read this article about CORS
You may be trying to pass headers or login with PUT. In this case, you must have https set and the response headers:
Access-Control-Allow-Credentials: true // Можно ли авторизовываться или нет
Access-Control-Allow-Origin: https://localhost:63343
Access-Control-Allow-Methods: PUT, OPTIONS
Access-Control-Allow-Headers: Content-Type, ... прочие заголовки, например Authorization или тот в котором логин и пароль
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question