【发布时间】:2015-02-22 19:16:09
【问题描述】:
我正在使用volley 库向服务器发出发布请求。这个库使用Map<String, String> 作为发布参数。我的问题是想为同一个键有多个值,可以使用NameValuePairs,但不能与 volley 一起使用。提前致谢!
【问题讨论】:
标签: android hashmap http-post android-volley basicnamevaluepair
我正在使用volley 库向服务器发出发布请求。这个库使用Map<String, String> 作为发布参数。我的问题是想为同一个键有多个值,可以使用NameValuePairs,但不能与 volley 一起使用。提前致谢!
【问题讨论】:
标签: android hashmap http-post android-volley basicnamevaluepair
尝试覆盖下面的方法,它来自源代码:
/**
* Returns the raw POST or PUT body to be sent.
*
* @throws AuthFailureError in the event of auth failure
*/
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = getParams();
if (params != null && params.size() > 0) {
return encodeParameters(params, getParamsEncoding());
}
return null;
}
返回要发送的原始 POST 或 PUT 正文。
所以用你的参数覆盖getBody()。
【讨论】:
getBody() 构造你的NameValuePairs 然后将其转换为byte array,或者构造类似"key=value1&key=value2" 然后将其转换为字节数组。