java调用URL
关键类
public String Get_Http(String tUrl) throws IOException{ URL url = new URL(tUrl); URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.setConnectTimeout(3000); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8"); // send data to page out.write("username=kevin&password=*********"); // remember to clean up out.flush(); out.close(); // this methos can receive msg while the responses is success! String sCurrentLine = ""; String sTotalString = ""; InputStream l_urlStream; l_urlStream = connection.getInputStream(); BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream)); while ((sCurrentLine = l_reader.readLine()) != null) { sTotalString += sCurrentLine+"/r/n"; } return sTotalString; }

浙公网安备 33010602011771号