Can't get HttpPost to work on Ice Cream Sandwich

Put your problem here if it does not fit any of the other categories.

Can't get HttpPost to work on Ice Cream Sandwich

Postby icydash » Sun Jun 03, 2012 6:48 pm

Hey guys, I'm having trouble getting my code working on ICS. It worked perfectly on my old DroidX, but I just got the new Galaxy Nexus and my code just returns null every time, as if the app isn't connecting to my servers or it's using a GET request when it should be using POST. Below is my code, any help is appreciated:

Code: Select all
   //---------------- AUTHENTICATE LOGIN ---------------------------
    public static String authenticateLogin (String usr, String password, String updateDataNames, String updateDataUsernames, String updateDataPhone, String updateDataRadius, String updateDataChecked, String updateGPS)
       String result = "";
       ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
      pairs.add(new BasicNameValuePair("LoginUSR", usr));
      pairs.add(new BasicNameValuePair("LoginPASS", password));
      pairs.add(new BasicNameValuePair("Names", updateDataNames));
      pairs.add(new BasicNameValuePair("Usernames", updateDataUsernames));
      pairs.add(new BasicNameValuePair("Phone", updateDataPhone));
      pairs.add(new BasicNameValuePair("Radius", updateDataRadius));
      pairs.add(new BasicNameValuePair("Checked", updateDataChecked));
      pairs.add(new BasicNameValuePair("GPS", updateGPS));
         HttpClient client = new DefaultHttpClient();
         HttpPost post = new HttpPost("http://www.[URL REMOVED].com/file.php");
         post.setEntity(new UrlEncodedFormEntity(pairs));
         HttpResponse response = client.execute(post);
         HttpEntity entity = response.getEntity();
         final InputStream is = entity.getContent();
         BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
         StringBuilder sb = new StringBuilder();
           String line = null;
           while ((line = reader.readLine()) != null) {

      catch(Exception e)
         Log.e("log_tag", "Error in http connection "+e.toString());
       return result;

EDIT: This thread better describes the problem I'm having and the reason why: ... -ics-fails

Apparently I can not do networking on main thread, I have to move it to a background thread, or use AsyncTask. I'm really not sure what either of those things mean / how to do them (newbie programmer here). Any help is appreciated.
Posts: 35
Joined: Thu Jun 09, 2011 1:22 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], MSNbot Media and 22 guests