0

I want to append a list list_id=[11111,2222,3333] to url it should look like below

http://1abc/spm//lookup/ids/xyz?list_id=[11111,2222,3333].

what should be the best and easiest way to do it ?

vahdet
  • 6,357
  • 9
  • 51
  • 106
shubham
  • 23
  • 1
  • 6
  • 3
    Possible duplicate of [How can I append a query parameter to an existing URL?](https://stackoverflow.com/questions/26177749/how-can-i-append-a-query-parameter-to-an-existing-url) – luk2302 Apr 01 '19 at 11:50

3 Answers3

0

It is good to use http POST type request to deal with this kind of input data.

  • what "kind of input data"? Lists? If I want to search for items with either ID 1 or 2 or 3 a GET with a list of these ids is perfectly fine. – luk2302 Apr 01 '19 at 11:52
0

To send special characters in a query parameter url encoding is used.

URL encoded URL will look like below. http://1abc/spm//lookup/ids/xyz?list_id=%5B11111%2C2222%2C3333%5D

Usually servers are supposed to handle url encoding.

nuwan
  • 90
  • 7
0

a) First, you need to understand that http supports sending the same parameter multiple times to constitute a list. You case is not new. This is how it normally would appear:

xyz?list_id=11111&list_id=2222&list_id=3333

On the server side, the code would have to use getValues(String param) -> String[] (or whatever api they have).

b) If you insist on a proprietary list format, you will have to urlencode each key and value independently, as usual, which means '[' as %5B and ']' as %5D (along with other unsafe chars). https://en.wikipedia.org/wiki/Percent-encoding

xyz?list_id=%5b11111%2c2222%2c3333%5d

The server side has to getValue(param) (typically urldecoded already) and will have to parse further your custom format (for which you could easily forget the [ ] since they are not helping).

Note: I assumed you are not asking about how to use StringBuilder.append()...lol

user2023577
  • 1,752
  • 1
  • 12
  • 23