1. Check out our companion app, Forums for Android! Download from Google Play

HttpPost problems...

Discussion in 'Application Development' started by ninjasenses, Jul 5, 2010.

  1. ninjasenses

    ninjasenses Active Member
    Thread Starter
    15

    Feb 9, 2010
    38
    0
    15
    Im posting to a webhandler using the HttpPost, although for some reason the way I am doing it, I am not getting the correct response. Is there A way I can view the actual POST it is making? or the query string url?

    Code (Text):
    1.  public void postData() {
    2.         // Create a new HttpClient and Post Header
    3.         HttpClient httpclient = new DefaultHttpClient();
    4.         HttpPost httppost = new HttpPost("http://0.0.0.0/Android/Login.ashx");
    5.  
    6.         try {
    7.             EditText username = (EditText)findViewById(R.id.username);
    8.             EditText password = (EditText)findViewById(R.id.password);
    9.            
    10.             // Add your data
    11.             List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    12.             nameValuePairs.add(new BasicNameValuePair("un", username.getText().toString()));
    13.             nameValuePairs.add(new BasicNameValuePair("pw", password.getText().toString()));
    14.             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    15.            
    16.             HttpParams params = new BasicHttpParams();
    17.             params.setParameter("un", username.getText().toString());
    18.             params.setParameter("un", password.getText().toString());
    19.             httppost.setParams(params);
    20.            
    21.             // Execute HTTP Post Request
    22.             HttpResponse response = httpclient.execute(httppost);
    23.            
    24.             String text = ResponseHandler.getResponseBody(response);
    25.             //long length = response.getEntity().getContentLength();
    26.  
    27.  
    28.            
    29.         } catch (ClientProtocolException e) {
    30.             // TODO Auto-generated catch block
    31.             e.printStackTrace();
    32.         } catch (IOException e) {
    33.             // TODO Auto-generated catch block
    34.             e.printStackTrace();
    35.         }
    36.     }
    I tested the web handler url with http://0.0.0.0/Android/Login.ashx?un=blah&pw=blah and it displayed correctly so I know there is no problem there. Any help would be greatly appreciated.
     

    Advertisement

  2. ninjasenses

    ninjasenses Active Member
    Thread Starter
    15

    Feb 9, 2010
    38
    0
    15
    I found the problem was actually with the way I was handling this on the web handler. I wasnt able to figure out how to get the post data on the web handler side, so I did a GET with the parameters as query strings instead and it worked fine
     

Share This Page

Loading...