zoukankan      html  css  js  c++  java
  • Android学习笔记【05】【网络编程之二】

    一、

    二、乱码问题解决

    URLEncoder进行URL编码:

    1 static String encode(String s, String charsetName);

    三、以httpClient方式提交数据到服务器

    Get方式:

     1 //URL地址
     2 String path="http://xxx.xx.x.xx:xxx/xxx/xx";
     3 //获取HttpClient实例(HttpClient是接口)
     4 DefaultHttpClient client=new DefaultHttpClient();
     5 //定义HttpGet请求
     6 HttpGet get=new HttpGet(path);
     7 //执行Get请求,获取响应
     8 HttpResponse response=client.execute(get);
     9 //获取状态码
    10 int code = response.getStatusLine().getStatusCode();
    11 //获取数据流
    12 InputStream input=response.getEntity().getContent();

    POST方式:

     1 //URL地址
     2 String path="http://xxx.xx.x.xx:xxx/xxx/xx";
     3 //获取HttpClient实例
     4 DefaultHttpClient client=new DefaultHttpClient();
     5 //定义HttpGet请求
     6 HttpPost post=new HttpPost(path);
     7 
     8 //准备数据
     9 List<NameValuePair> list=new ArrayList<NameValuePair>();
    10 BasicNameValuePair nameValuePair=new BasicNameValuePair("name","zhangsan");
    11 BasicNameValuePair passwordValuePair=new BasicNameValuePair("password","123");
    12 
    13 list.Add(nameValuePair);
    14 list.Add(passwordValuePair);
    15 
    16 UrlEncodeFormEntity entity=new UrlEncodeFormEntity(list);
    17 //执行Post请求,获取响应
    18 HttpResponse response=client.execute(post);
    19 //获取状态码
    20 int code = response.getStatusLine().getStatusCode();
    21 //获取数据流
    22 InputStream input=response.getEntity().getContent();

    四、开源项目方式提交数据到服务器

    asyncHttpClient

    五、JavaSE多线程下载

    六、断点续传实现

    Activity类getCacheDir()和getFilesDir()方法:
    getCacheDir()方法用于获取/data/data/<package name>/cache目录
    getFilesDir()方法用于获取/data/data/<package name>/files目录

  • 相关阅读:
    A Bayesian Approach to Deep Neural Network Adaptation with Applications to Robust Automatic Speech Recognition
    nnet3的代码分析
    Kaldi中的L2正则化
    HMM拓扑与转移模型
    Kaldi阅读并更改代码
    nnet3中的数据类型
    nnet3配置中的“编译”
    Kaldi的delta特征
    Kaldi的交叉熵正则化
    【搜索】 Prime Path
  • 原文地址:https://www.cnblogs.com/leishoulin/p/7430203.html
Copyright © 2011-2022 走看看