这是我的代码,目的是在滨州学院图书馆的新书通报中找有关鲁迅的书 用程序的到的结果是说暂时没有内容而在浏览器中却可以搜到很多书 ,这是怎么回事呢 ,请求熟悉的哥哥们赐教呀,十万火急呀!
public class Test2 { public static void main(String[] args) throws Exception {

HttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost("http://10.9.10.3/museweb/xstb/xstb.asp");

List<NameValuePair> list = new ArrayList<NameValuePair>();

NameValuePair pair = new BasicNameValuePair("txtWxlx", "CN");

NameValuePair pair2 = new BasicNameValuePair("txtTm", "鲁迅");



list.add(pair);
list.add(pair2);

HttpEntity entity = new UrlEncodedFormEntity(list);

post.setEntity(entity);

HttpResponse  response = client.execute(post);

String html =new String(EntityUtils.toByteArray(response.getEntity()));

System.out.println(html);

}
}

解决方案 »

  1.   

    你要确定http://10.9.10.3/museweb/xstb/xstb.asp 请求流写出来的是什么东西?
      

  2.   

    我不大了解这其中的细节,运行之后返回的是一个正常的html页面但是不是正常应该返回的页面。
      

  3.   

    解决了,原来是发送post时没有对entity进行编码才导致返回的信息不对,HttpEntity entity = new UrlEncodedFormEntity(list);这一行改成HttpEntity entity = new UrlEncodedFormEntity(list,"gb2312");就行了