Multiple Parameters with Net:Http

Is there a way to pass in 2 parameters with the same name to the
Net::Http client in ruby?
It’s using a map right now, and it only stores one of the values.
Is this a bug in the Http client implementation?
The http spec allows you to pass in multiple parameters with the same
name.

def get_data(data, in_only=‘Y’)
one = Time.new
url = URI.parse(‘http://127.0.0.1/ec/data.xml’)
req = Net::HTTP::Post.new(url.path)
req.basic_auth ‘user’, ‘pass’
req.set_form_data({‘test’=>1, ‘test’=>2})
res = Net::HTTP.new(url.host, url.port).start {|http|
http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
xml = res.body
else
res.error!
end
end

On 19.04.2007 23:53, [email protected] wrote:

url = URI.parse('http://127.0.0.1/ec/data.xml')
end

end

Without trying I’d assume that it should work like this:

req.set_form_data({‘test’=>[1, 2]})

btw, you can leave out the curlys

req.set_form_data(‘test’=>[1, 2])

Kind regards

robert

On Apr 20, 4:00 am, Robert K. [email protected] wrote:

  xml = res.body

req.set_form_data(‘test’=>[1, 2])

Kind regards

    robert

Here is the ruby program I’m trying to run, and the Java Program that
explains what I am trying to do a little better.

require ‘net/http’
url = URI.parse(“http://localhost/test/scott.jsp”)
req = Net::HTTP::Post.new(url.path)
req.set_form_data({‘test’=>[‘1’,‘2’]})
res = Net::HTTP.new(url.host, url.port).start {|http|
http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
xml = res.body
else
res.error!
end
puts xml

Here is the java jsp i’m testing it with.

<%
StringBuffer sb = new StringBuffer();
String[] values = request.getParameterValues(“test”);
sb.append(values.length + " ");
for(int i=0;i<values.length;i++)
sb.append(values[i] + " ");
%>
<%=sb.toString()%>

I would expect values to be an array with 2 items in it.

When I run the program I get back a single value with “12” in it.
instead of 2 separate values with “1” and “2” in them.

The query string in the browser would look like “http://localhost/test/
scott.jsp?test=1&test=2”
But i’d like to do that in ruby with a post request.

Thanks for the help.

On 25.04.2007 00:05, [email protected] wrote:

name.
xml = res.body
req.set_form_data(‘test’=>[1, 2])
url = URI.parse(“http://localhost/test/scott.jsp”)
puts xml
%>

Thanks for the help.

First I’d make sure your JSP actually behaves as expected, i.e. detects
multiple values properly. For example, you could do something like this

<%= Arrays.asList( request.getParameterValues(“test”) ) %>

This should print a comma separated and bracket enclosed list.

Only then I’d continue to work on the Ruby side.

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs