Using HttpClient and HttpPost in Android with post parameters

后端 未结 4 1706
花落未央
花落未央 2020-11-29 02:06

I\'m writing code for an Android application that is supposed to take data, package it as Json and post it to a web server, that in turn is supposed to respond with json.

4条回答
  •  离开以前
    2020-11-29 02:33

    have you tried doing it without the JSON object and just passed two basicnamevaluepairs? also, it might have something to do with your serversettings

    Update: this is a piece of code I use:

    InputStream is = null;
    ArrayList nameValuePairs = new ArrayList();
        nameValuePairs.add(new BasicNameValuePair("lastupdate", lastupdate)); 
    
    try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(connection);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.d("HTTP", "HTTP: OK");
        } catch (Exception e) {
            Log.e("HTTP", "Error in http connection " + e.toString());
        }
    

提交回复
热议问题