package com.andela.webservice;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Spykins on 08/06/16.
 */
public class HttpManager {

    public static String getData(String uri) {

        BufferedReader reader = null;
        try{
            URL url = new URL(uri);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            StringBuilder sb = new StringBuilder();
            reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String line;
            while((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            return sb.toString();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        /*
            //More on HTTPURLCONNECTION

        HttpURLConnection connection = null;
        String responseContent = null;
        StringBuilder builder = new StringBuilder();

        try {
            URL url = new URL(uri);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");

            builder.append(connection.getResponseCode())
                    .append(" ")
                    .append(connection.getResponseMessage())
                    .append("\n");

            //This gets the header and prints the content of the Header.....
            Map<String, List<String>> map = connection.getHeaderFields();
            for (Map.Entry<String, List<String>> entry : map.entrySet())
            {
                if (entry.getKey() == null)
                    continue;
                builder.append( entry.getKey())
                        .append(": ");

                List<String> headerValues = entry.getValue();
                Iterator<String> it = headerValues.iterator();
                if (it.hasNext()) {
                    builder.append(it.next());

                    while (it.hasNext()) {
                        builder.append(", ")
                                .append(it.next());
                    }
                }

                builder.append("\n");
            }

                   return connection.getInputStream().toString();
            //This returns the

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(connection != null) {
                connection.disconnect();
            }
        }

        return builder.toString();
        }
        */
        return null;
    }

}

@@ -26,16 +26,45 @@
 vice;%0A%0A%0A
+import android.util.Base64;%0A%0A
 import j
@@ -2825,10 +2825,1645 @@
 %0A    %7D%0A%0A
+    public static String getData(String uri, String userName, String password) %7B%0A%0A        BufferedReader reader = null;%0A        byte%5B%5D loginByte = (userName + %22:%22 + password).getBytes();%0A        //Now we have a byte Array represent the credentials..%0A        StringBuilder loginBuilder = new StringBuilder()%0A                .append(%22Basic %22)%0A                .append(Base64.encodeToString(loginByte, Base64.DEFAULT));%0A        //Now the loginBuilder contains the credential, encoded and ready to send to the webServer%0A%0A        try%7B%0A            URL url = new URL(uri);%0A            HttpURLConnection con = (HttpURLConnection) url.openConnection();%0A            /*%0A                Before connecting with the connection Object, we need to set a request property%0A                The header value... The header value will have a name of Authorisation and a value%0A                created by the loginBuilder object%0A             */%0A%0A            con.addRequestProperty(%22AUTHORIZATION%22, loginBuilder.toString());%0A            //Now as long as we connect with the correct userName and password...%0A            // you should be able to connect and get data back%0A%0A            StringBuilder sb = new StringBuilder();%0A            reader = new BufferedReader(new InputStreamReader(con.getInputStream()));%0A            String line;%0A            while((line = reader.readLine()) != null) %7B%0A                sb.append(line + %22%5Cn%22);%0A            %7D%0A            return sb.toString();%0A        %7D catch (MalformedURLException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A
 %7D%0A

Create a new getData method which takes user name and password for authentication