日期:2014-05-20  浏览次数:20874 次

httpclient 乱码问题
asp 页面

 title = request.Form("Title")
  If title="" then
  Response.end()
  End If
Response.Write title

t = "中国";
HttpClient http = new HttpClient();
PostMethod post = new PostMethod("http://127.0.0.1/post.asp");
NameValuePair id = new NameValuePair("ChannelID", "1");
NameValuePair classid = new NameValuePair("ClassID", "248");
NameValuePair st = new NameValuePair("Title", t);
NameValuePair data = new NameValuePair("HtmlFileDate", yyyy+mm+dd+String.valueOf(System.currentTimeMillis()));
NameValuePair content = new NameValuePair("TextContent", c);
post.setRequestBody(new NameValuePair[] {id,classid, st,content,data});
http.executeMethod(post);
System.out.println(post.getStatusCode()+"----------");
String str = new String(post.getResponseBodyAsString().getBytes("iso-8859-1"),"GBK");
System.out.println(str+"\n\n");

这里输出200----------
??
这乱码怎么解决啊
 
post.releaseConnection();



------解决方案--------------------
指定字符集

Java code
private static final String CONTENT_CHARSET = "GBK";// httpclient读取内容时使用的字符集
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, CONTENT_CHARSET);