Java URL Read getText(HttpURLConnection conn)

Here you can find the source of getText(HttpURLConnection conn)

Description

get Text

License

Open Source License

Declaration

public static StringBuffer getText(HttpURLConnection conn) 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;

public class Main {
    public static StringBuffer getText(HttpURLConnection conn) {
        try {//from ww w  .j  a  v a 2s .  c  o m
            int rc = conn.getResponseCode();
            String s = "";
            StringBuffer html = new StringBuffer();
            try {
                BufferedReader inp = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                while ((s = inp.readLine()) != null) {
                    s = s.replaceAll("http://istgeo.ist.supsi.ch:80/basemaps/wms/", "ciao");
                    System.out.println(s);
                    html.append(s);
                }
                inp.close();
                return html;
            } catch (Exception e) {
                System.out.println(e.getLocalizedMessage());
            }
        } catch (IOException e) {
            System.out.println(e.getLocalizedMessage());
        }
        return new StringBuffer();
    }
}

Related

  1. getRemoteFileLength(String url)
  2. getRemoteFileSize(URL url)
  3. getStreamByConnection(final HttpURLConnection con)
  4. getStringFromConnection(HttpURLConnection connection)
  5. getStringFromURL(String URLString)
  6. getText(String url)
  7. getText(String url)
  8. getText(URL url)
  9. getTextFromURL(final String url)