【发布时间】:2012-07-06 05:24:49
【问题描述】:
我已经看过很多论坛帖子并尝试了一些建议,但我仍然无法解决这个问题。该代码在我的家庭系统中运行良好,但在组织防火墙后面它给出了一条异常消息:
没有可用于 NTLM @proxy.tcs.com:8080 的凭据
这是我正在使用的方法
private static void UseAbdera() throws IOException
{
try
{
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
client.setProxy("OrgProxyHost", 8080);
NTLMAuthenticatorClass authenticator = new NTLMAuthenticatorClass("username", "password");
Authenticator.setDefault(authenticator);
NTCredentials ntcr = new NTCredentials("username", "password", "greenhouse.lotus.com", "India.TCS.com");
client.addCredentials("https://greenhouse.lotus.com", null, null, ntcr);
ClientResponse resp = client.get("https://greenhouse.lotus.com/forums/atom/service");
org.apache.abdera.model.Document<org.apache.abdera.model.Service> service_doc = resp.getDocument();
service_doc.writeTo(System.out);
System.out.println("\n");
org.apache.abdera.model.Service service = service_doc.getRoot();
org.apache.abdera.model.Collection collection = service.getCollection("Forums Feed Collection", "My Topics");
String coll_uri = collection.getResolvedHref().toASCIIString();
org.apache.abdera.model.Entry entry = abdera.newEntry();
entry.setTitle("TEST REPLY !");
// Mark private
resp = client.post(coll_uri, entry);
switch (resp.getType())
{
case SUCCESS:
String location = resp.getLocation().toASCIIString();
System.out.println("New entry created at: " + location);
break;
default:
System.out.println("Error: " + resp.getStatusText());
}
} catch (URISyntaxException ex)
{
Logger.getLogger(IBMConnectionMessages_ForumPractice.class.getName()).log(Level.SEVERE, null, ex);
}
}
这是我得到的异常日志
org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme 信息:已选择 ntlm 身份验证方案 2012 年 7 月 6 日上午 10:42:03 org.apache.commons.httpclient.HttpMethodDirector processProxyAuthChallenge 信息:没有可用于 NTLM @orgProxyHost 的凭据:8080 线程“主”java.lang.IllegalStateException 中的异常 在 org.apache.abdera.protocol.client.CommonsResponse.(CommonsResponse.java:44) 在 org.apache.abdera.protocol.client.AbderaClient.execute(AbderaClient.java:692) 在 org.apache.abdera.protocol.client.AbderaClient.get(AbderaClient.java:216) 在 org.apache.abdera.protocol.client.AbderaClient.get(AbderaClient.java:404) 在 IBMConnectionMessages_ForumPractice.UseAbdera(IBMConnectionMessages_ForumPractice.java:231) 在 IBMConnectionMessages_ForumPractice.main(IBMConnectionMessages_ForumPractice.java:45)
请帮忙,我花了半天时间。
【问题讨论】:
-
我不熟悉
AbderaClient,但看起来它只是 apache httpclient 3 的包装器? (或者可能是 4 个?)你试过client.getState().setProxyCredentials()吗? -
是的,我试过了,最初我创建了一个 HttpClient 并使用接受 HTTPClient 作为参数的构造函数创建了 AbderaClient。在那里我也设置了 proxyCredentials。
-
使用 setProxyCredentials 后我收到了这个 > 使用 NTLM 进行身份验证失败 @proxy.tcs.com:8080
标签: httpclient ntlm apache-abdera