0

I have a site that I would like to log into. Once there, I would parse the code to display member data (like any other login app). I have sort of pulled this code from somewhere and I'd like to know why it's crashing. Basically, I have two login inputs, username and password. I'll take them from the user but as of now I'm just inputting random credentials for testing. At the end, I want to get it to the login page (same url once logged in) and display the HTML, for now.

Here's my code so far:

HttpClient httpClient = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), TIMEOUT_MS);
    HttpConnectionParams.setSoTimeout(httpClient.getParams(), TIMEOUT_MS);
    HttpPost httpPost = new HttpPost("login url");  // Removed for StackOverflow question
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
    nameValuePairs.add(new BasicNameValuePair("sid", "name"));  
    nameValuePairs.add(new BasicNameValuePair("pin", "pass"));
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
    HttpResponse response = httpClient.execute(httpPost);
    BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()), 8096);
    tvStatus.setText((CharSequence) br);
Mark Lyons
  • 1,324
  • 5
  • 20
  • 54

2 Answers2

2

Are you running the POST request on the UI thread? This causes the UI to freeze and after a certain time period, the OS considers the app to be non-responsive and force closes it. Web Requests should always be an Async task

xbonez
  • 40,730
  • 48
  • 157
  • 236
  • Hey, thanks for your help. I found some different code which seems to be doing more. Please take a look at my question http://stackoverflow.com/questions/9952869/android-login-to-website-always-returns-login-page- and see if you notice the problem. Thanks! – Mark Lyons Mar 31 '12 at 03:50
1

I guess this post on my blog will help you to understand, how to use AsyncTask, for downloading stuff.

Though if you tell us what is the Exception which is getting thrown up, I could've helped you more on this. To see the Exception, open the LogCat,identify the error text which will be in red, copy the whole red text and paste it into your question.

noob
  • 18,447
  • 20
  • 113
  • 179