zoukankan      html  css  js  c++  java
  • 使用HttpURLConnection发送POST请求

    通过URL访问其他电脑或者服务器上的方法:

    URL url = new URL("http://20.10.3.23:6060/call/geometryGroupOperater.op?action=queryMapPointsGroups");
    HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
    urlcon.setRequestMethod("POST");
    urlcon.setDoOutput(true);// 是否输入参数

    StringBuffer params1 = new StringBuffer();
    // 表单参数与get形式一样
    params1
    .append("xs=").append(xs).append("&")
    .append("ys=").append(ys).append("&")
    .append("groupIds=").append(groupIds);
    System.out.println(params1.toString());
    byte[] bypes = params1.toString().getBytes();
    urlcon.getOutputStream().write(bypes);// 输入参数
    urlcon.connect(); //获取连接
    InputStream is = urlcon.getInputStream();

    BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
    StringBuffer bs = new StringBuffer();
    String l = null;
    while((l=buffer.readLine())!=null){
    bs.append(l);
    }
    System.out.println(bs.toString());

  • 相关阅读:
    Go基础
    格式化输入输出
    常量
    Go语言基础之变量
    跨平台编译
    Hello World
    使用go module导入本地包
    Go语言之依赖管理
    Go包管理
    Go项目结构
  • 原文地址:https://www.cnblogs.com/latter/p/5490160.html
Copyright © 2011-2022 走看看