我想使用此 NameValuePair
方法从我的 Android 客户端向 Web 服务器发送几个值:
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
}
}
不幸的是 NameValuePair
只能发送字符串,我还需要发送整数值。
最佳答案
您好 hectichavana 如果您想使用名称值对发送整数值,您可以这样尝试
nameValuePairs.add(new BasicNameValuePair("gender",Integer.toString(1)));
其中 gender 代表键,1 将成为该键的值。 希望对您有所帮助。
关于android - 使用 NameValuePair 将整数发送到 HTTP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8603583/