我有一个运行在Heroku上的Java应用程序,它需要访问Salesforce,它只允许您从白名单中的IP访问API。比昔莫是一个Heroku外接程序,允许您通过一个静态IP服务器代理应用程序提出的所有请求。不幸的是,这样做的标准方法是在Proximo的包装器中运行应用程序-mucks为我的应用程序的way服务器对很多人来说创建一个监听套接字。
如何在Java应用程序中使用Proximo作为SOCKS代理?
发布于 2014-02-19 16:47:25
我查看了他们分发的堆垛作为前面提到的包装器,并看到它以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;
}
}https://stackoverflow.com/questions/21886916
复制相似问题