我在
需要身份验证的服务上运行与Google Cloud有关的CORS相关问题。
如果我尝试通过带有Bearer令牌的cli执行curl命令,则
一切正常。不幸的是,如果我尝试通过javascript中的ajax执行相同的调用,则会
收到403。
const http = new XMLHttpRequest();
const url = 'https://my-app.run.app';
http.open("GET", url);
http.withCredentials = true;
http.setRequestHeader("authorization", 'Bearer ' + id_token);
http.send();
http.onreadystatechange = (e) => {
console.log(http.responseText)
}
Run Code Online (Sandbox Code Playgroud)
云运行日志中的错误是这样的:
The request was not authenticated. Either allow unauthenticated invocations or set the proper Authorization header. Read more at https://cloud.google.com/run/docs/securing/authenticating
Run Code Online (Sandbox Code Playgroud)
容器永远不会被击中。
我看到的问题是,当我在Web
浏览器中使用Ajax拨打电话时。Web浏览器正在发出飞行前请求(
网址上的OPTIONS ),而没有发送Authorization标头(这是预期的
行为)
问题似乎是,云运行尝试对OPTIONS
请求进行身份验证,并且从未将其发送到我的容器中,据我所知,这
不应完成。(
https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0)
那是云运行的已知问题吗?
我如何向经过身份验证的云运行服务发出ajax请求?
我有一个问题,并想问你们为什么这些代码不起作用,如何在不删除泛型或方法的情况下使其工作.我认为这是因为该方法不能重载,因为S和T可以是同一类型,是否正确?但我仍然不知道如何让它发挥作用.谢谢!
public class GenericFail<S,T> {
public void doAnything(S sValue){
System.out.println("Doing anything with S");
}
public void doAnything(T sValue){
System.out.println("Doing anything with T");
}
}
Run Code Online (Sandbox Code Playgroud)