首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

httpclient 乱码有关问题

2012-03-20 
httpclient 乱码问题asp 页面title request.Form(Title)If title thenResponse.end()End IfRespons

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); 

热点排行