Passing String array in get request in url

Hi,

I have a web service exposed in my local box and am trying to send a get request to that service which takes GET requests.

The following url works :
http://localhost:8080/myapp/tremor.htm?startDate=17-Oct-2011&endDate=17-Oct-2011&apiNames=references

but the apiNames in the above url is actually a String array.  I could only pass one string but here i need to pass a collection of apiNames in the url.  I tries the following things but it didn't work for me.

apiNames=[references, services]
apiNames=[references, services]
apiNames=[[references], [services]]
apiNames={references, services}

Can any one help me the correct syntax to pass a String array in url ?

-Murali.
lakkarajumuraliAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:
maybe this will work like in this case:
http://stackoverflow.com/questions/5484209/pass-array-as-a-parameter-in-restful-webservice
      

You have a few options here.
Option 1: A query parameter with multiple values

You can supply multiple simple values for a single query parameter. For example, your query string might look like:

PUT /path/to/my/resource?param1=value1&param1=value2&param1=value3

Here the request parameter param1 has three values, and the container will give you access to all three values as an array (See Query string structure).
0
 
for_yanCommented:
see also here
http://en.wikipedia.org/wiki/Query_string#Structure


Multiple values can also be associated with a single field:

    field1=value1&field1=value2&field1=value3...

For each field of the form, the query string contains a pair field=value. Web forms may include fields that are not visible to the user; these fields are included in the query string when the form is submitted

This convention is a W3C recommendation.[3] W3C recommends that all web servers support semicolon separators in the place of ampersand separators.[4]

Technically, the form content is only encoded as a query string when the form submission method is GET. The same encoding is used by default when the submission method is POST, but the result is not sent as a query string, that is, is not added to the action URL of the form. Rather, the string is sent as the body of the HTTP request.
0
 
lakkarajumuraliAuthor Commented:
Thank you it worked!!
0
 
CEHJCommented:
>>PUT /path/to/my/resource?param1=value1&param1=value2&param1=value3

You don't want to do that probably. The GET query string is already limited in length as it is.

More likely your problem was caused by incorrect url-encoding of the query string
0
 
lakkarajumuraliAuthor Commented:
Hi Cehj,

the service accepts GET requests and it does not allow the user to create or update the data in the db but we get data from that service.  The solution which Yan send me work perfectly fine and as such we will be sending not more than 3 values in an array which is well within 255 char deadline.

Thank you all for the reply.

Murali.
0
All Courses

From novice to tech pro — start learning today.