【发布时间】:2010-09-03 15:04:56
【问题描述】:
我想创建一个小型 Java 应用程序来将一些 wiki 内容从一台服务器复制到另一台服务器。 API 是based on the XML-RPC。
基本上我有三种方法,login、getPage 和putPage。我使用Apache HttpClient 3.x 并设法使用login 成功登录并使用getPage 从旧wiki 正确获取页面。
身份验证通过 cookie 处理:我登录到新的 wiki,并在相应的 httpclient 上设置了一些 cookie。 doku 告诉我其中一个 cookie 用于身份验证。
然后我在同一个 httpclient 上使用另一个 POST 方法执行putPage,服务器以身份验证失败消息进行响应。
代码序列是这样的(非常简化):
HttpClient client = new HttpClient();
PostMethod postLogin = createNewPostMethod("login", "user", "pw");
client.executeMethod(postLogin);
// Now I'm logged in and the client definitly has stored the cookies
PostMethod postPutPage = createNewPostMethod("putPage", getPage());
client.executeMethod(postPutPage); // the server won't let me put the page
应该这样工作还是我必须手动将 cookie 添加到第二个 post 方法,如果是,如何?
编辑/解决方案
在这个问题的答案的帮助下,我能够识别和解决问题,这超出了 httpclient 的使用范围。最后,这是目标 wiki 端的配置问题。这里的答案帮助我在另一个论坛中提出了正确的问题。
【问题讨论】:
标签: java httpclient xml-rpc