使用java發送HTTP請求

來源:互聯網
上載者:User

標籤:readline   exception   http   input   method   list   edr   inpu   style   

 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 }

 

使用java發送HTTP請求

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.