本帖最后由 ylca 于 2016-7-14 16:22 编辑
- public static String myHttpGet(String adderss ,String param) {
- String target= adderss +"?"+param;
- URL url;
- try {
- String result = "";
- url = new URL(target.toString());
- HttpURLConnection urlConn = (HttpURLConnection) url
- .openConnection(); //创建一个HTTP连接
- InputStreamReader in = new InputStreamReader(
- urlConn.getInputStream()); // 获得读取的内容
- BufferedReader buffer = new BufferedReader(in); // 获取输入流对象
- String inputLine = null;
- //通过循环逐行读取输入流中的内容
- while ((inputLine = buffer.readLine()) != null) {
- result += inputLine + "\n";
- }
- in.close(); //关闭字符输入流对象
- urlConn.disconnect(); //断开连接
- return result;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
-
- }
复制代码 用来获取我们需要的网页内容!!!
|
|