1

I have to send bulk data items via url to process in server side.

Is it possible to send using get method?

 list1 = ["string1","string2","string3","string4"]
 list2 = ["domain_string1","domain_string2"]

 url = http://127.0.0.1/search?l=list1&l2=list2

How these lists should be passed?

These list of items will grow dynamically.sometime we will get 10 items in each list

suggest me the way?

Nava
  • 6,276
  • 6
  • 44
  • 68

2 Answers2

4

In general, it's best to avoid long query strings in GET requests. A great question for reference on this is the SO question What is the maximum length of a URL?. You don't want to exceed 2000 characters.

If your items will always fit in this length, you can use urllib.urlencode to convert your parameters:

>>> list1 = ["string1","string2","string3","string4"]
>>> list2 = ["domain_string1","domain_string2"]
>>> allparams = map(lambda x: ("list1", x), list1)
>>> allparams += map(lambda x: ("list2", x), list2)
>>> import urllib
>>> urllib.urlencode(allparams)
'list1=string1&list1=string2&list1=string3&list1=string4&list2=domain_string1&list2=domain_string2'

Instead, you could use a POST request. I highly recommend the requests library:

import requests
r = requests.post("http://127.0.0.1/search", data=allparams)
Community
  • 1
  • 1
jterrace
  • 64,866
  • 22
  • 157
  • 202
  • The appropriate way to send them would be ?l1=string1&l1=string2&l2=string3, etc. That's the standard for URL formatting. – Jordan Mar 27 '12 at 15:57
  • Right, I forgot that you can duplicate query params. I've updated the answer. – jterrace Mar 27 '12 at 16:08
0

You can send it all with the same url variable name

"http://localhost/search?urlvar=1&urlvar=2&urlvar=3"

request.GET.getlist("urlvar");

Alberto Perez
  • 1,019
  • 15
  • 17