有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

google app engine在Java ManagedVM url获取请求中缺少入站应用id头

我有一个Java应用程序在App Engine的ManagedVM上运行。我目前正试图让它调用我的应用程序中的另一个模块。该模块使用X-Appengine-Inbound-Appid头的值作为安全性,以确保只有其他模块可以调用该端点。但是,我的请求中没有正确设置此标题。我遵循了urlfetch指令,包括按照指令设置connection.setInstanceFollowRedirects(false);,但仍然没有设置头

有没有关于可能出现什么问题的想法

    URL url = new URL("https", hostname, "/path");

    HttpURLConnection connection = (HttpURLConnection)url.openConnection();

    connection.setInstanceFollowRedirects(false);

    String value = req.getHeader("My-Header");
    if (value != null) {
        connection.setRequestProperty("My-Header", value);
    }

    int respCode = connection.getResponseCode();
    if (respCode != 200) {
        resp.sendError(respCode, "invalid response code from upstream");
        return;
    }

    // use the successful response...

共 (1) 个答案

  1. # 1 楼答案

    我能够通过直接使用URLFetchService而不是java.net.URL来解决这个问题。我的猜测是,在托管VMs应用程序中,您可以使用url包发出常规网络请求(不设置X-Appengine-Inbound-Appid头),并且必须直接使用URLFetchService才能通过url获取基础设施