Java URL Query queryHtml(String url)

Here you can find the source of queryHtml(String url)

Description

query Html

License

Apache License

Declaration

public static String queryHtml(String url) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static String queryHtml(String url) throws IOException {
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setInstanceFollowRedirects(true);
        int code = connection.getResponseCode();
        if (code == 200) {
            InputStream in = connection.getInputStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int len;
            while ((len = in.read(buffer)) != -1) {
                out.write(buffer, 0, len);
            }/*  w w w.  j  av a2  s .  c om*/
            return out.toString();
        }
        System.out.println("url:" + url + "   code:" + code);
        throw new IOException("error");
    }
}

Related

  1. query(URL host, String endpoint, String customer, String name, OutputStream out)
  2. queryEndpoint(String url)
  3. appendQueryParams(String url, Map params)
  4. getHTTPQuery(String urlToRead)
  5. getQueryParams(String url)
  6. search(String query, int numberOfUrls)