Java XML Data Type Converter getText(URL url, String user, String password)

Here you can find the source of getText(URL url, String user, String password)

Description

get Text

License

Apache License

Declaration

public static String getText(URL url, String user, String password) throws IOException 

Method Source Code


//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();
    }
}

Related

  1. getByteList(String nomal, boolean isDecode)
  2. getByteListStr(List byteList, boolean isEncode)
  3. getDataUrlForBytes(final byte[] bytes)
  4. getImgurContent(String clientID, byte[] image)
  5. getLong(byte[] data)
  6. getTextAsJavaByteArrayInitializer( String text, String charsetName, int maxArraySize)
  7. getXMLLong(final long value)
  8. isValidValue(String value, Class type)
  9. millis2String(long millis)