Ok, I seemed to have figured it out. I went down a few different paths after getting Will's answer yesterday, but alas most of them didn't even get me close. Some of them would change the error code from 500 to 401, but those were also changing the desired use of the BufferedInputStream. Regardless, if you want to use a BufferedInputStream, with a URLConnection, and include authentication for things such as Cloudant or whatever the case may be, you need to use setRequestProperty. Now, with that said, I tried this route a few different ways and adding the user and password in and doing a base64 switch after the connection has been made and the url was passed into the function didn't work at all. So, if you are able to pass the key/pass in with the URL as I originally had, the following will work perfectly for you... in theory (It is what worked for me anyhow).
if (url.getUserInfo() != null) {
String basicAuth = "Basic " + new String(Base64.encode(url.getUserInfo().getBytes(), 0));
conn.setRequestProperty("Authorization", basicAuth);
}
And of course, here it is implemented in my function so you can get the full effect.
public static String getURLStringResponse(URL url)
{
String response = "";
try {
URLConnection conn = url.openConnection();
// THIS WAS THE MAGIC ENTRY
if (url.getUserInfo() != null) {
String basicAuth = "Basic " + new String(Base64.encode(url.getUserInfo().getBytes(), 0));
conn.setRequestProperty("Authorization", basicAuth);
}
// END OF MAGIC CHANGE
BufferedInputStream bin = new BufferedInputStream(conn.getInputStream());
byte[] contentBytes = new byte[1024];
int bytesRead = 0;
StringBuffer responseBuffer = new StringBuffer();
while ((bytesRead = bin.read(contentBytes)) != -1)
{
response = new String(contentBytes, 0, bytesRead);
responseBuffer.append(response);
}
return responseBuffer.toString();
} catch (Exception e) {
// TODO: handle exception
Log.e(TAG, "getURLStringResponse Error as Follows");
Log.e(TAG, e.toString());
}
return response;
}
I really hope this helps some of you out.