1 Public classTest {2 Public Static voidMain (string[] args) {3BufferedReader in =NULL;4String result = "";5 Try {6String Path = "http://127.0.0.1:6666/webapp/servlet/workItemServlet?method=gotWorkItem&dataTime=05-01";7URL Realurl =NewURL (path);8URLConnection connection =realurl.openconnection ();9Connection.setrequestproperty ("Accept", "*/*");TenConnection.setrequestproperty ("Connection", "keep-alive"); OneConnection.setrequestproperty ("User-agent", "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.1; SV1) "); A Connection.connect (); -in =NewBufferedReader (NewInputStreamReader (Connection.getinputstream (), "UTF-8")); - String Line; the while(line = In.readline ())! =NULL) { -Result + =Line ; - } -list<object> list = Jsonutil.toobjectlist (result, Object.class); + for(Object obj:list) { - System.out.println (obj.tostring ()); + } A}Catch(Exception e) { atSystem.out.println ("12345 WorkItem Find Error"); -}finally { - Try { - if(In! =NULL) { - in.close (); - } in}Catch(Exception E2) { - e2.printstacktrace (); to } + } - } the}
Sending HTTP requests using Java