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