Hi,i'm using httpclient to connect a url. The problem is that i accept a error
redirect location ,for example http://wapp.baidu.com/f?kw=???????? , when to
visit the url.
the url to visit
is:http://gate.baidu.com/tc?m=2&w=0_5_%E5%93%80%E9%B8%A3&t=wap&ssid=0&from=0&bd_page_type=0&p=b43ed516d9c21fff57ee96685c52&order=2&vit=osres&uid=wap_1237916098_46&src=http%3A%2F%2Fpost%2Ebaidu%2Ecom%2Ff%3Fkw%3D%B9%C2%D1%E3%B0%A7%C3%F9
why there appeared some characters like "???????? "? The correct redirect
laoction should be http://wapp.baidu.com/f?kw=%B9%C2%D1%E3%B0%A7%C3%F9.
thd exception is:
org.apache.commons.httpclient.InvalidRedirectLocationException: Invalid
redirect location: http://wapp.baidu.com/f?kw=????????
at
org.apache.commons.httpclient.HttpMethodDirector.processRedirectResponse(HttpMethodDirector.java:619)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:179)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at cn.rjb.app.test.TestClickA.getSourceCode(TestClickA.java:28)
at cn.rjb.app.test.TestClickA.main(TestClickA.java:15)
Caused by: org.apache.commons.httpclient.URIException: Invalid query
at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)
at org.apache.commons.httpclient.URI. <init>(URI.java:147)
at
org.apache.commons.httpclient.HttpMethodDirector.processRedirectResponse(HttpMethodDirector.java:601)
... 5 more
the code i use is :
public static void main(String args[]) {
// the url will be to visit
String requestURL =
"http://gate.baidu.com/tc?m=2&w=0_5_%E5%93%80%E9%B8%A3&t=wap&ssid=0&from=0&bd_page_type=0&p=b43ed516d9c21fff57ee96685c52&order=2&vit=osres&uid=wap_1237916098_46&src=http%3A%2F%2Fpost%2Ebaidu%2Ecom%2Ff%3Fkw%3D%B9%C2%D1%E3%B0%A7%C3%F9";
// use httpclient to get the response of the url
String response = null ;
HttpClient httpClient = new HttpClient();
GetMethod method = new GetMethod(requestURL);
try {
httpClient.executeMethod(method);
response = new String(method.getResponseBody(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
method.releaseConnection();
}
// print the response ,if ok
System.out.println(response);
}