我正在尝试通过我的 java 代码连接到 Google Api,并且为此使用 apache Camel。我必须首先在代理服务器上进行身份验证,然后请求将转发到谷歌。但是,尽管我提供了我的凭据,但我无法实现身份验证。
context.getProperties().put("http.proxyAuthMethod","Digest");
context.getProperties().put("http.proxyHost", "foo");
context.getProperties().put("http.proxyPort", "80");
context.getProperties().put("http.proxyAuthUsername",
"bar");
context.getProperties().put("http.proxyAuthPassword", "foo");
我也尝试过使用 HTTP Endpoint
HttpEndpoint endpoint = (HttpEndpoint) context.getEndpoint("https://foo/bar");
Map<String, Object> options = new HashMap<String, Object>();
options.put("proxyAuthUsername","foo");
options.put("proxyAuthPassword","bar");
options.put("proxyAuthMethod","Basic");
endpoint.configureProperties(options);
endpoint.setProxyHost("foo");
endpoint.setProxyPort(80);
我仍然收到 407 响应代码,以及一条需要代理进行身份验证的消息。任何人都可以给我指点一下吗?
谢谢
最佳答案
昨晚我终于让代理代码工作了,尽管我不知道为什么上述两种方法不起作用。但我开始使用 Spring XML 配置文件进行 Camel 路由,并且我能够通过以下配置来实现这一目标:
<camel:to uri="http://www.google.com/search?proxyAuthMethod=Basic&proxyPort=xx&proxyHost=xxxxxxx&proxyAuthUsername=username&proxyAuthPassword=password" />
关于java - Apache Camel : Proxy code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191789/