HttpClient post 关于post数据为中文的问题 这个星期的工作要做个meta Search,我用HttpClient写了个简单的demo,但是一个网站需要post,但是其中一个parameter在post中文的时候老是得不到结果,不知道怎么回事(英文是可以的) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 UrlEncoder好象也不怎么行啊,是不是我的代码有问题,下面是部分代码HttpClient httpClient = new HttpClient(); String url = "http://book.du8.com/book/BookSearch.do"; String keyword = "中国"; keyword = java.net.URLEncoder.encode(keyword,"GBK"); System.out.println(keyword); PostMethod method = new PostMethod(url); //填入各个表单域的值 /*NameValuePair[] data = {new NameValuePair("queryType", "bkname"), new NameValuePair("keyword", "tcp"),new NameValuePair("secondQuery","true"), new NameValuePair("operator","and"),new NameValuePair("ljjs.x","57"),new NameValuePair("ljjs.y","7")}; */ NameValuePair[] data = {new NameValuePair("selectSearch", "bookName")}; method.setQueryString(new NameValuePair[]{new NameValuePair("keyword", keyword)}); //将表单的值放入postMethod中 method.setRequestBody(data); method.setFollowRedirects(false); //执行method StringBuffer resultBuffer = new StringBuffer(); try { httpClient.executeMethod(method); BufferedReader in = new BufferedReader( new InputStreamReader( method.getResponseBodyAsStream(), method.getResponseCharSet())); String inputLine = null; while ((inputLine = in.readLine()) != null) { //inputLine = ConverterStringCode(inputLine,method.getResponseCharSet(),"gb2312"); resultBuffer.append(inputLine); resultBuffer.append("\n"); } in.close(); System.out.println(resultBuffer.toString()); FileWriter write = new FileWriter("d:\\test\\test.txt"); write.write(resultBuffer.toString()); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } jquery.tablesorter.js 怎么控制每页显示的条数哦? outputstream的问题,请教 简单问题 如何制作下拉菜单快捷键 Java JFrame的问题。。。 java简单的问题 这种方法要jdk什么版本才支持 求助,包含ImageIO类的方法不能运行? 谁能帮我看看这个Applet程序那里出错了? eclipse的中文教程有没有的,相关帮助也行 初中生都会的题,你会吗? JAVA的一些小问题
HttpClient httpClient = new HttpClient();
String url = "http://book.du8.com/book/BookSearch.do";
String keyword = "中国";
keyword = java.net.URLEncoder.encode(keyword,"GBK");
System.out.println(keyword);
PostMethod method = new PostMethod(url);
//填入各个表单域的值
/*NameValuePair[] data = {new NameValuePair("queryType", "bkname"),
new NameValuePair("keyword", "tcp"),new NameValuePair("secondQuery","true"),
new NameValuePair("operator","and"),new NameValuePair("ljjs.x","57"),new NameValuePair("ljjs.y","7")};
*/
NameValuePair[] data = {new NameValuePair("selectSearch", "bookName")};
method.setQueryString(new NameValuePair[]{new NameValuePair("keyword", keyword)});
//将表单的值放入postMethod中
method.setRequestBody(data);
method.setFollowRedirects(false);
//执行method
StringBuffer resultBuffer = new StringBuffer();
try {
httpClient.executeMethod(method);
BufferedReader in = new BufferedReader(
new InputStreamReader(
method.getResponseBodyAsStream(),
method.getResponseCharSet()));
String inputLine = null;
while ((inputLine = in.readLine()) != null) {
//inputLine = ConverterStringCode(inputLine,method.getResponseCharSet(),"gb2312");
resultBuffer.append(inputLine);
resultBuffer.append("\n");
}
in.close();
System.out.println(resultBuffer.toString());
FileWriter write = new FileWriter("d:\\test\\test.txt");
write.write(resultBuffer.toString());
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}