Android · 2013/05/03

HttpGet方法中的中文处理

上回说到HttpPost中通过json发送中文的问题(这里),这次说个HttpGet的处理,比如要百度搜索“您好”:

http://www.baidu.com/s?wd=%E6%82%A8%E5%A5%BD&rsv_sug3=5

 

android是这样处理的(不用解释了吧):

——————————-

List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair(“wd”,”您好”));
qparams.add(new BasicNameValuePair(“rsv_sug3″,”5”));
URI uri = URIUtils.createURI(“http”,”www.baidu.com”, -1, “s”,
URLEncodedUtils.format(qparams, “gbk“),null);
HttpGet httpGet = new HttpGet(uri);
HttpResponse httpResponse= new DefaultHttpClient().execute(httpGet);
String result = EntityUtils.toString(httpResponse.getEntity());