【发布时间】:2012-09-12 23:52:02
【问题描述】:
我正在尝试访问特定的网址
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(new AuthScope("abc.com", 443),
new UsernamePasswordCredentials("user", "Passwd"));
HTTPHelper http = new HTTPHelper(httpclient);
http.get("http://abc.com/**aaa**/w/api.php?param=timestamp%7Cuser&format=xml");
%7C= |
在内部将我重定向到以下网址
http://abc.com/**bbb**/w/api.php?param=timestamp%257Cuser&format=xml
因此我无法获得正确的输出...
| ==>%7C
%==> %25
%7C == %257C
我希望查询为timestamp|user
但由于循环重定向,它变成了timestamp%7Cuser
有什么办法可以避免吗?
我也编写了自己的自定义重定向策略
httpclient.setRedirectStrategy(new DefaultRedirectStrategy() {
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) {
boolean isRedirect = false;
try {
isRedirect = super.isRedirected(request, response, context);
LOG.info(response.getStatusLine().getStatusCode());
LOG.info(request.getRequestLine().getUri().replaceAll("%25", "%"));
} catch (ProtocolException e) {
e.printStackTrace();
}
if (!isRedirect) {
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode == 301 || responseCode == 302) {
return true;
}
}
return isRedirect;
}
});
但我不确定如何将 %25C 替换为来自重定向 url 的 %7C
【问题讨论】:
标签: http url redirect httpclient mediawiki