//打开restful链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          
// 提交模式
conn.setRequestMethod("PUT");//POST GET PUT DELETE
          
//设置访问提交模式,表单提交
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
          
conn.setConnectTimeout(10000);//连接超时 单位毫秒
conn.setReadTimeout(2000);//读取超时 单位毫秒
          
conn.setDoOutput(true);// 是否输入参数

StringBuffer params = new StringBuffer();
// 表单参数与get形式一样
params.append("customer").append("=").append(1);
byte[] bypes = params.toString().getBytes();
conn.getOutputStream().write(bypes);// 输入参数

读取返回的值:

//读取请求返回值
InputStream inStream=conn.getInputStream();
inStream.read(bypes, 0, inStream.available());
System.out.println(new String(bypes, "gbk"));

相关文章:

  • 2022-12-23
  • 2022-02-22
  • 2022-12-23
  • 2022-01-02
  • 2022-01-17
  • 2021-12-05
猜你喜欢
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案