通过 httpclient 3.x 模拟 HTTP POST 以获得多个选项
我想使用 application/x-www-form-urlencoded 编码模拟 HTTP POST 发送允许多项选择的选项组。
<select name="groups" multiple="multiple" size="4">
<option value="2">Administration</option>
<option value="1">General</option>
</select>
添加 2 个同名的 NameValuePairs (NVP) 是否有效?我的服务器端日志显示仅收到第一个 NVP。
例如,
PostMethod method = ...;
NameValuePair[] nvpairs = {
new NameValuePair( "groups", "2" );
new NameValuePair( "groups", "1" );
};
method.addParameter( nvpairs );
仅收到 groups=1 参数。谢谢
I want to emulate a HTTP POST using application/x-www-form-urlencoded encoding
to send a option group that allows multiple selections.
<select name="groups" multiple="multiple" size="4">
<option value="2">Administration</option>
<option value="1">General</option>
</select>
Does adding 2 NameValuePairs (NVP) with the same name work ? My serverside log shows that only the first NVP was received.
e.g
PostMethod method = ...;
NameValuePair[] nvpairs = {
new NameValuePair( "groups", "2" );
new NameValuePair( "groups", "1" );
};
method.addParameter( nvpairs );
Only the groups=1 parameter was received. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更有可能的是,您的服务器代码正在调用
ServletRequest.getParameter()
而不是getParameterValues()
。但最好的验证方法是使用 HTTP 代理(例如 Fiddler)来查看实际请求。
编辑:正确的
HttpClient
方法是addParameters()
,而不是addParameter()
- 您的代码显示后者,但我不相信它会编译,所以假设您复制不正确。More likely is that your server code is calling
ServletRequest.getParameter()
rather thangetParameterValues()
.But the best way to verify is use an HTTP proxy such as Fiddler to look at the actual request.
Edit: the correct
HttpClient
method isaddParameters()
, notaddParameter()
-- your code shows the latter, but I don't believe it would compile so am assuming you copied incorrectly.