Here you can find the source of getText(URL url, String user, String password)
public static String getText(URL url, String user, String password) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static String getText(URL url, String user, String password) throws IOException { final StringBuffer buffer = new StringBuffer(); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //authentication String userpass = user + ":" + password; String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes()); connection.setRequestProperty("Authorization", basicAuth); //read response final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = reader.readLine(); while (line != null) { buffer.append(line);/*ww w .j a v a 2 s. c o m*/ line = reader.readLine(); } reader.close(); return buffer.toString(); } }