zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    块结构在文件中的表示IOB【转载】
    LSTM输入层、隐含层及输出层参数理解【转载】
    L3-002 特殊堆栈 (30 分) 模拟stl
    L1-006 连续因子 (20 分) 模拟
    L2-014 列车调度 (25 分)
    L3-021 神坛 (30 分) 计算几何
    P1156 垃圾陷阱 DP
    P1063 能量项链 区间dp
    P1040 加分二叉树 区间dp
    P1605 迷宫 dfs回溯法
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5186048.html
Copyright © 2011-2022 走看看