gpt4 book ai didi

spring - 使用 Spring RestTemplate 时未设置“X-Appengine-Inbound-Appid” header

转载 作者:行者123 更新时间:2023-12-02 17:10:41 27 4
gpt4 key购买 nike

我在 Google App Engine 上运行了两项服务(MS1 和 MS2)。 MS1 部署在标准环境中,MS2 部署在灵活环境中。我正在调用从标准环境到灵活环境的 API。我想确保 MS2 只接受来自 MS1 的请求。所以,我决定使用 this App Engine 的功能。我在 MS1 中将 X-Appengine-Inbound-Appid header 和 setInstanceFollowRedirects 设置为 false,但看起来 App Engine 正在删除此 header 。我无法在 MS2 中找到此 header 。

HttpHeaders headers = new HttpHeaders();
headers.add("X-Appengine-Inbound-Appid", ApiProxy.getCurrentEnvironment().getAppId());
HttpEntity<MergePdfsResource> entity = new HttpEntity<MergePdfsResource>(mergePdfsResource, headers);

restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory() {
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
super.prepareConnection(connection, httpMethod);
connection.setInstanceFollowRedirects(false);
}
});

ResponseEntity<SomeClass> response = restTemplate.postForEntity(apiUrl, entity, SomeClass.class);

最佳答案

以下是我从 Google 支持部门得到的答复:

只有在我们使用 URLFetch 服务时才会设置 X-Appengine-Inbound-Appid header 。在java8运行环境中,默认是native,使用标准的Java网络类。因此,我必须在 appengine-web.xml 中将 URL 流处理程序设置为 urlfetch,如下所示:

<url-stream-handler>urlfetch</url-stream-handler>

关于spring - 使用 Spring RestTemplate 时未设置“X-Appengine-Inbound-Appid” header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49483822/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com