Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/**
*
*/
package de.tutorials;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
/**
* @author daritho
*
*/
public class HttpBasicAuthenticationExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("USERNAME","PASSWORD".toCharArray());
}
});
URL url = new URL("http://www.somewhere.com/secured_area");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
while((line = br.readLine())!= null){
System.out.println(line);
}
br.close();
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class Auth{
public Auth() {
}
private void fetchURL (String urlString) {
try {
URL url = new URL (urlString);
String userPassword = getPasswordAuthentication();
// Encode String
String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
// Need to work with URLConnection to set request property
URLConnection uc = url.openConnection();
uc.setRequestProperty ("Authorization", "Basic " + encoding);
InputStream content = (InputStream)uc.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
String getPasswordAuthentication() {
return "Username:pw";
}
public static void main (String args[]) {
Auth x = new Auth();
x.fetchURL("http://www.xzy.at");
}
}