nonopo12345 wrote:
??2009-03-30??"Oleg Kalnichevski" <[email protected]> ??????
On Sat, 2009-03-28 at 22:50 +0800, nonopo12345 wrote:
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.
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.
This is most likely because the redirect location in the HTTP response
is not correctly escaped. HTTP messages are expected to consist of
US-ASCII characters only. Non-US-ASCII characters are supposed to be
escaped.
Oleg
how can httpclient escape Non-US-ASCII characters correctly ?
HttpClient handles redirects correctly. It is the server side script
that appears broken. The redirect MUST be correctly escaped on the
server side.
Oleg
could you give me a example on visiting this url
: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
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);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]