【发布时间】:2013-02-03 13:39:50
【问题描述】:
我想添加一个 Hashtable 作为 NameValuePair 的值,如下所示:
name= credit_card
value(this is the hashtable)= {expirationDate="2013/02/18", ownerName="Jack Sparrow", typeOfCard="C2"}
或者像这样:
new BasicNameValuePair("credit_card",{expirationDate="2013/02/18", ownerName="Jack Sparrow", typeOfCard="C2"})。
这是我的代码的一部分,你可以看到我是如何添加一个简单的 NameValuePair 的:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://example.com/register");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("user", user));
nameValuePairs.add(new BasicNameValuePair("password", password));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
提前致谢!
【问题讨论】:
-
“添加哈希”是什么意思?
-
hash你在说什么? -
问题已编辑,谢谢!
-
如您所见,BasicNameValuePair 构造函数是 BasicNameValuePair(String name, String value) hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/…
-
@Carlos - 您是否尝试使用键“credit_card”添加 JSON 字符串的哈希值,作为 BasicNameValuePair?基本上是 new BasicNameValuePair("credit_card", hash(json))?
标签: java android httpclient hashtable