• android http 通信(java原生类库实现)


    get方式

    private void doGet(){
      URL httpurl = new URl(url);   
      HttpURLConnection  conn = (HttpURLConnection)httpUrl.openConnection();
      conn.setRequestMethod("GET");
      conn.setReadTimeout(5000);
      BufferedReader reader = new BuffedReader(new InputStreamReader(conn.getInputStream));
      String str;
      StringBuffer sb = new StringBuffer();
      while((str = reader.readLine()) != null){
         sb.append(str);  
      }
    }

    post方式

    private void doPost(){
      URL httpUrl = new URL(url);
      HttpURLconnection conn = (HttpURLConnection)  httpUrl.openConnection();
      conn.setRequestMethod("POST");
      conn.setReadTimeout(5000);
      OutputStream out = conn.getOutputStream();
      String content = "name"+name+"age"+age;
      out.write(content.getBytes());   BufferedReader reader
    = new BufferedReader(new InputStreamReader(conn.getInputStream()));   StringBuffer sb = new StrintgBuffer();   String str;   while((str = reader.readLine())!=null){     sb.append(str);   } }

    服务器端解决乱码问题

    String name = request.getParameter("name");
    response.setContentType("text/html;charset=utf-8");
    PrintWriter out = response.getWriter();
    name = new String(name.getBytes("iso-8859-1"),"utf-8");

    android解决乱码问题

    get方式:URLEncoder.encode(name,"utf-8");
    post方式:不会产生乱码,因为android系统默认使用utf-8编码

    获取android系统默认配置信息

    Properties property = System.getProperties();
    property.list(System.out);
  • 相关阅读:
    go 基本类型
    slice底层实现
    数组Array
    GO内置类型和函数
    python 操作es
    go 相关命令
    Init函数和main函数
    切片
    RecursionError: maximum recursion depth exceeded
    多项式工业基础与全家桶
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5186048.html
Copyright © 2020-2023  润新知