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

     1 public class Test {
     2     public static void main(String[] args) {
     3         BufferedReader in = null;
     4         String result = "";
     5         try {
     6             String path = "http://127.0.0.1:6666/webapp/servlet/workItemServlet?method=gotWorkItem&dataTime=05-01";
     7             URL realUrl = new URL(path);
     8             URLConnection connection = realUrl.openConnection();
     9             connection.setRequestProperty("accept", "*/*");
    10             connection.setRequestProperty("connection", "Keep-Alive");
    11             connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
    12             connection.connect();
    13             in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
    14             String line;
    15             while ((line = in.readLine()) != null) {
    16                 result += line;
    17             }
    18             List<Object> list = JsonUtil.toObjectList(result, Object.class);
    19             for (Object obj : list) {
    20                 System.out.println(obj.toString());
    21             }
    22         } catch (Exception e) {
    23             System.out.println("12345 workItem find error");
    24         } finally {
    25             try {
    26                 if (in != null) {
    27                     in.close();
    28                 }
    29             } catch (Exception e2) {
    30                 e2.printStackTrace();
    31             }
    32         }
    33     }
    34 }
  • 相关阅读:
    关于编码的问题(转)
    XML巩固
    浏览器兼容问题的解决方案
    JavaScript 全局变量命名空间生成函数
    表格的使用(转)
    post上传文件
    安装cocoapods
    UILabel内容模糊
    动态获取键盘高度
    iOS多线程同步锁
  • 原文地址:https://www.cnblogs.com/yanwu0527/p/9128063.html
Copyright © 2011-2022 走看看