i have a problem with cors. I would like to call an endpoint which is on another domain1 (can't change to https) from a other domain2.
Is it possible ?
I have this error :
> Access to XMLHttpRequest at
> 'http://192.168.1.140:8090/app1/auth/login' from origin 'http://app2'
> has been blocked by CORS policy: Response to preflight request doesn't
> pass access control check: No 'Access-Control-Allow-Origin' header is
> present on the requested resource
App1 : vuejs with axios
axios
.post('/auth/login', {
username: username,
password: password
})
App2 : java with jersey
Updated 19/03 15:40:
@OPTIONS
@Path("/login")
public Response login() {
return Response.status(200).header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
.build();
}
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
@Path("/login")
public Response login(@FormParam("username") String username, @FormParam("password") String password) {
return Response
.status(200)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
.build();
}
Updated 19/03 16:08
I deleted two lines in vuejs
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.token;
Now it's work But how can i call an http endpoint from https?
Thank you