我正在尝试访问特定的 url
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;
}
});
但我不确定如何从重定向的 url 用 %7C 替换 %25C