Java tutorial
//package com.java2s; //License from project: Open Source License import java.net.HttpURLConnection; import java.net.URL; import android.util.Base64; public class Main { static void setBasicAuthentication(HttpURLConnection conn, URL url) { String userInfo = url.getUserInfo(); if (userInfo != null && userInfo.length() > 0) { String authString = Base64.encodeToString(userInfo.getBytes(), Base64.DEFAULT); conn.setRequestProperty("Authorization", "Basic " + authString); } } }