将数据传递到键值对

时间:2013-03-28 13:45:13

标签: android http-post

如何通过在Android中的HttpPost中使用“=”代替“:”来传递键值对中的数据?

像这样:

"firstName" = "abc"
"lastName" = "xyz"

1 个答案:

答案 0 :(得分:1)

我不知道你用“=”代替“:”是什么意思,但我的猜测是你试图用参数发布。你可以试试这样的东西:

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
nameValuePairs.add(new BasicNameValuePair("firstName", "abc"));
nameValuePairs.add(new BasicNameValuePair("lastName", "xyz"));
try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    httpClient.execute(httpPost);
}