当前位置: 代码迷 >> J2SE >> httpclient 乱码有关问题
  详细解决方案

httpclient 乱码有关问题

热度:365   发布时间:2016-04-24 01:47:53.0
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);
  相关解决方案