我已经看过很多论坛帖子,并尝试了几个建议,但我仍然无法解决这个问题。该代码在我的家庭系统中运行良好,但在组织防火墙后面它提供了一条异常消息:
没有可用于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 线程“main”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)
请帮忙,我花了半天时间。
答案 0 :(得分:0)
您的代理可能需要ntlm身份验证,因此在设置代理凭据时请将您的代理身份验证详细信息作为NTCredentials提供。