• 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;

    }
  • 相关阅读:
    家庭记账本1
    寒假福利5
    寒假福利4——定位功能
    寒假福利3——日期时间选择器
    寒假作业——家庭小账本1.6(总结)
    寒假作业——家庭小账本1.5
    寒假作业——家庭小账本1.4
    寒假作业——家庭小账本1.3
    寒假作业——家庭小账本1.2
    寒假作业——家庭小账本1.1
  • 原文地址:https://www.cnblogs.com/to-creat/p/5683720.html
Copyright © 2020-2023  润新知