Emulating HTTP POST via httpclient 3.x for multi options
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">
&l开发者_StackOverflowt;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
More likely is that your server code is calling ServletRequest.getParameter()
rather than getParameterValues()
.
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 is addParameters()
, not addParameter()
-- your code shows the latter, but I don't believe it would compile so am assuming you copied incorrectly.
精彩评论