zoukankan      html  css  js  c++  java
  • URLConnection格式与用法

    private void getdialog() {
    final EditText et = new EditText(this);
    final String workid = this.workid;
    new AlertDialog.Builder(this).setTitle("请输入面积").setView(et).
    setPositiveButton("确定", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface arg0, int arg1) {
    final String size = et.getText().toString();
    new Thread() {
    @Override
    public void run() {
    httpget(workid, size);
    }
    }.start();
    //Log.i("size",size);

    }
    }).show();
    }

    public String httpget(String workid, String size) {

    String result = "";
    BufferedReader in = null;
    StringBuilder buf = new StringBuilder("http://www.agribiotech.cn/record/record/sizerecord");
    buf.append("?");
    buf.append("workid=" + workid + "&");
    buf.append("size=" + size);


    try {
    URL url = null;
    url = new URL(buf.toString());
    URLConnection conn = url.openConnection();
    conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    conn.setRequestProperty("Accept", "application/json");
    conn.connect();
    Map<String, List<String>> map = conn.getHeaderFields();
    for (String key : map.keySet()) {
    System.out.println(key + "--->" + map.get(key));
    }
    in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = in.readLine()) != null) {
    result += " " + line;
    }

    } catch (IOException e) {
    Log.i("warn", e.toString());
    e.printStackTrace();
    } finally {
    try {
    if (in != null) {
    in.close();
    }
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    }
    return result;

    }
  • 相关阅读:
    LeetCode 226. Invert Binary Tree
    LeetCode 221. Maximal Square
    LeetCode 217. Contains Duplicate
    LeetCode 206. Reverse Linked List
    LeetCode 213. House Robber II
    LeetCode 198. House Robber
    LeetCode 188. Best Time to Buy and Sell Stock IV (stock problem)
    LeetCode 171. Excel Sheet Column Number
    LeetCode 169. Majority Element
    运维工程师常见面试题
  • 原文地址:https://www.cnblogs.com/to-creat/p/5683720.html
Copyright © 2011-2022 走看看