0

编辑:固定。看看有什么问题,看看这个

当我尝试使用 Authorization 标头向 FastHttp 服务器发送请求时,标头会被删除。当我使用 Postman 发送请求时,Authorization 标头不会被删除。

为了查看实际发送了哪些标头,我设置了一个 Undertow Web 服务器(Java)并将我的请求发送到该服务器。

Java网络服务器的代码:

Undertow undertow = Undertow.builder().addHttpListener(55446, "localhost", new HttpHandler() {
    public void handleRequest(final HttpServerExchange httpServerExchange) throws Exception {
        System.out.println("------------------------------------------");
        System.out.println("Con from "+httpServerExchange.getHostName());
        System.out.println("Query "+httpServerExchange.getQueryString());
        System.out.println("Header "+httpServerExchange.getRequestHeaders().getHeaderNames().stream().map(str -> str.toString()+": "+httpServerExchange.getRequestHeaders().get(str).element()).collect(Collectors.joining("; ")));
        httpServerExchange.getRequestReceiver().receiveFullString((httpServerExchange1, s) -> System.out.println("Body "+s));

        httpServerExchange.setStatusCode(400);
    }
}).build();
undertow.start();

当我使用 Postman 发送请求时的输出:

------------------------------------------
Con from localhost
Query 
Header Accept: */*; Postman-Token: 275ba9bb-77cc-4c9f-baa5-653f60162551; Connection: keep-alive; Authorization: Bearer xxxxxxxxxxxxxxxxxxxxx; Cache-Control: no-cache; Accept-Encoding: gzip, deflate; User-Agent: PostmanRuntime/7.21.0; Host: localhost:55446
Body 

当我使用我的应用程序发送请求时输出:

------------------------------------------
Con from localhost
Query 
Header test: f; Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml; Authorization: Bearer testtoken; Accept-Encoding: gzip, deflate; User-Agent: VSpedSync/DevBuild; Host: localhost:55446
Body 

在这两种情况下,都会发送授权标头,但是当我将请求发送到 FastHttp 服务器时,只有来自 Postman 的请求包含标头。

我很困惑,为什么会发生这种情况?

4

0 回答 0