Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by gonzalo ( 13 years ago )
public static String getRequest(String url,String username, String password){
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString="";
try {
String authorization = android.util.Base64.encodeToString((username+":"+password).getBytes("UTF-8"),android.util.Base64.NO_WRAP);
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Content-Type", "application/json");
httpGet.addHeader("Authorization", "Basic "+ authorization);
response = httpclient.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = out.toString();
out.close();
}
else{
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return responseString;
}
Revise this Paste