HTTPS Tomcat重新路由请求

问题描述 投票:0回答:1

我有一个当前在Tomcat网络服务器上运行的应用程序。我的应用程序向具有IP速率限制的网站api发出https请求。

我想通过将我的https流量重新路由到代理服务器来解决这个问题,但我遇到了一些困难。

Tomcat是否能够通过设置-Dhttps.proxyHost和-Dhttps.proxyPort来实现这一点,还是需要在代码中实现?

我目前正在使用okhttp3和改造来制作api请求。我也可以使用我正在使用的代理来重新路由请求。

任何帮助/指导将不胜感激。

java tomcat https okhttp3
1个回答
0
投票

这么晚才回复很抱歉...

您的应用程序应该进行代理,一种方式可以是循环,即每个请求api服务器从代理地址和端口列表中获取下一个代理。比如:

public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
  Proxy proxyTest = new Proxy(Proxy.Type.HTTP,new InetSocketAddress("proxy", proxyPort));

  OkHttpClient client = new OkHttpClient()
  .proxy(proxyTest)
  .build();

  String post(String url, String json) throws IOException {

    RequestBody body = RequestBody.create(JSON, json);
    Request request = new Request.Builder()
        .url(url)
        .post(body)
        .build();
    try (Response response = client.newCall(request).execute()) {
      return response.body().string();
    }
  }

HTH,Gal

© www.soinside.com 2019 - 2024. All rights reserved.