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;

    }
  • 相关阅读:
    【Java123】enum枚举及其应用
    sql查询优化_慢查询
    9.4 如何实现属性可修改的函数装饰器?
    9.2 如何为被装饰的函数保存元数据?
    python的如何通过实例方法名字的字符串调用方法?
    9.1 如何使用函数装饰器 用装饰器解决重复计算问题
    asyncio 笔记
    python笔记截图
    list绑定
    表单数据交互
  • 原文地址:https://www.cnblogs.com/to-creat/p/5683720.html
Copyright © 2011-2022 走看看