I've been working on an android app, and recently got all of the login code working using HttpClient
. However, this code is now deprecated and no longer works. The language summary suggests replacing all HttpClient
code with HttpURLConnection
objects. I'm not sure how to do that though. If anyone could help me change my code to HttpURLConnection
to submit a login form and retrieve information, it would be greatly appreciated. here is my original use-to-function code:
String u = params[0];
String p = params[1];
DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,Boolean.TRUE);
//client.setRedirectStrategy(new LaxRedirectStrategy());
HttpPost post = new HttpPost("https://home-access.cfisd.net/HomeAccess/Account/LogOn");
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("LogOnDetails.Username", u));
list.add(new BasicNameValuePair("LogOnDetails.Password",p));
list.add(new BasicNameValuePair("Database","10"));
HttpResponse response = null;
try{
post.setEntity(new UrlEncodedFormEntity(list));
response = client.execute(post);
}
catch(Exception ex)
{
ex.printStackTrace();
}