Java URL Connection getString(URL url)

Here you can find the source of getString(URL url)

Description

get String

License

Open Source License

Declaration

public static String getString(URL url) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36";

    public static String getString(URL url) throws IOException {
        URLConnection page = url.openConnection();
        page.addRequestProperty("User-Agent", USER_AGENT);
        InputStream is = page.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String result = "";
        String line = "";
        while ((line = br.readLine()) != null) {
            result += line + "\r\n";
        }//from  w  w  w. j a  v  a2s  .co m
        is.close();
        return result;
    }
}

Related

  1. getRequest(URLConnection conn)
  2. getRequestHeaders(URLConnection conn)
  3. getResultsWithEncoding(URLConnection source, String encoding)
  4. getStream(URL url)
  5. getStreamWithTimeOut(String stringUrl, Integer timeOutInMilli)
  6. getType(URLConnection connection)
  7. getUrl(String serverName, String docid, String pageid)
  8. getURL(String url)
  9. getUrlAsProperties(String urlString)