gpt4 book ai didi

java - 如何在 Java 中使用 Proximo 作为 SOCKS 代理?

转载 作者:行者123 更新时间:2023-12-02 06:10:59 25 4
gpt4 key购买 nike

我有一个在 Heroku 上运行的 Java 应用程序,需要访问 Salesforce,该应用程序仅允许从您列入白名单的 IP 进行 API 访问。 Proximo是一个 Heroku 插件,允许您通过具有静态 IP 的单个服务器代理您的应用程序发出的所有请求。不幸的是,执行此操作的标准方法 - running your app within Proximo's wrapper - 为我的应用程序的网络服务器创建监听套接字的过程变得困惑,as it seems to for a number of folks .

如何在我的 Java 应用程序中使用 Proximo 作为 SOCKS 代理?

最佳答案

我看了stacklet他们将其作为上述包装器进行分发,并发现它作为 SOCKS 代理连接到 Proximo 服务器。这在 Java 中很容易做到,所以我将其添加到我的应用程序的启动中(Groovy 语法):

URL proximo = new URL(System.getenv('PROXIMO_URL')
String userInfo = proximo.getUserInfo()
String user = userInfo.substring(0, userInfo.indexOf(':'))
String password = userInfo.substring(userInfo.indexOf(':') + 1)
System.setProperty('socksProxyHost', proximo.getHost())
System.setProperty('socksProxyPort', '1080')
Authenticator.setDefault(new ProxyAuth(user, password))

将 ProxyAuth 作为其他地方的内部类:

private class ProxyAuth extends Authenticator {
private PasswordAuthentication passwordAuthentication;

private ProxyAuth(String user, String password) {
passwordAuthentication = new PasswordAuthentication(user, password.toCharArray())
}

@Override
protected PasswordAuthentication getPasswordAuthentication() {
return passwordAuthentication;
}
}

关于java - 如何在 Java 中使用 Proximo 作为 SOCKS 代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21886916/

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