I am making a app that requires login auth. And i have api:
curl --user username:password -X GET -http://sample.com
Now i want to auth the login and get the response.
I have look into this but am not getting any result.
I have done this. But it keep going on the catch block.
public static String getRequest() {
StringBuffer stringBuffer = new StringBuffer("");
BufferedReader bufferedReader = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet();
URI uri = new URI("http://sample.com");
httpGet.setURI(uri);
httpGet.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials("username", "password"),
HTTP.UTF_8, false));
HttpResponse httpResponse = httpClient.execute(httpGet);
InputStream inputStream = httpResponse.getEntity().getContent();
bufferedReader = new BufferedReader(new InputStreamReader(
inputStream));
String readLine = bufferedReader.readLine();
while (readLine != null) {
stringBuffer.append(readLine);
stringBuffer.append("\n");
readLine = bufferedReader.readLine();
}
} catch (Exception e) {
// TODO: handle exception
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
// TODO: handle exception
}
}
}
return stringBuffer.toString();
}
How can i accomplish this?
Thanks in Advance.