Hi, warum kann ich den Stream ausgeben,
aber nicht als String speichern?
aber nicht als String speichern?
Code:
import java.net.*;
import java.util.Scanner;
import java.io.*;
public class BasicAuth
{
public static InputStream openAuthorizedStream(
URL url, String user, String passwd ) throws IOException
{
String s = user + ":" + passwd;
String base64 = "Basic " +
new sun.misc.BASE64Encoder().encode( s.getBytes() );
URLConnection conn = url.openConnection();
conn.setRequestProperty( "Authorization", base64 );
conn.connect();
return conn.getInputStream();
}
public static void main( String[] args ) throws IOException
{
URL url = new URL( "http://www.gastrob.de/Subway......" );
InputStream stream = openAuthorizedStream( url, "****", "****" );
//GEHT!
System.out.println( new Scanner(stream).useDelimiter("\\Z").next().toString() );
//GEHT nicht!
String data = new Scanner(stream).useDelimiter("\\Z").next().toString();
String[] dataComponents = data.split("|");
for (int i = 0; i < dataComponents.length; i++) {
System.out.println(dataComponents[i]);
}
}
}