Sending a whole to an HTTP server using NameValuePair

I want to send a couple of values ​​to a web server from my Android client using this method NameValuePair:

public void postData() {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http:/xxxxxxx");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            String amount = paymentAmount.getText().toString();
            String email = inputEmail.getText().toString();
            nameValuePairs.add(new BasicNameValuePair("donationAmount", amount));
            nameValuePairs.add(new BasicNameValuePair("email", email));
            nameValuePairs.add(new BasicNameValuePair("paymentMethod", "5"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    } 

Unfortunately, it NameValuePaircan send String, I need to send Integer values ​​as well. Can someone help me solve my problem?

+5
source share
3 answers

Hi hectichavana If you want to send integer values ​​using a pair with a name, you can try how to do it

nameValuePairs.add(new BasicNameValuePair("gender",Integer.toString(1)));

where gender is the key, and 1 will be the value of this key. I hope for this help.

+13
source

, , , . , IMO, NameValuePair String. , String NameValuePair

new BasicNameValuePair("integer", new Integer().toString(value));

- , .

+2

, / , ints Strings . (, XML) .

+1

All Articles