zoukankan      html  css  js  c++  java
  • android url 中文请求,乱码解决

    解决乱码的代码:

       1:      private String connServerForResult(String url) {
       2:          String strResult = "";
       3:          try {
       4:              HttpClient httpClient = new DefaultHttpClient();
       5:              HttpPost httpPost = new HttpPost();
       6:              httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
       7:              httpPost.setURI(new URI(url));
       8:              
       9:              //httpPost,通过urlParam添加请求参数
      10:              List<NameValuePair> urlParam = new ArrayList<NameValuePair>();
      11:              
      12:              //中文内容,通过URLDecoder.decode转码
      13:              urlParam.add(new BasicNameValuePair("date", URLDecoder.decode(date_search.getText().toString(), "utf-8")));
      14:              
      15:              httpPost.setEntity( new UrlEncodedFormEntity(urlParam, HTTP.UTF_8));
      16:              HttpResponse response = httpClient.execute(httpPost);
      17:              HttpEntity entity = response.getEntity();
      18:              if (entity != null)
      19:                  strResult = EntityUtils.toString(entity, HTTP.UTF_8);
      20:          } catch (Exception e) {
      21:          }
      22:          return strResult;
      23:      }
  • 相关阅读:
    Action<T>和Func<T>的使用(转)
    javascript将网页表格导出Word(转载)
    jQuery扩展方法2(转载)
    Microsoft SQL Server 2008 安装说明
    INSERT INTO 语句的语法错误 access 保留字段
    .NET 验证控件
    TFS强制撤销用户的签出
    .net 操作XML
    TFS 恢复删除文件
    checkboxlist详细用法、checkboxlist用法、checkboxlist
  • 原文地址:https://www.cnblogs.com/shuanger/p/2811715.html
Copyright © 2011-2022 走看看