0

I'm designing an API, but here is a problem:

?merchantCategoryName=[Adult,Fantasy,Mac]
&mappedCategoryID=[701,80,22]
&merchantID=36330&outputType=xml

This is ideal situation, but what if merchantCategoryName contains a comma like this: (Ad,ult is a merchantCategoryName)

?merchantCategoryName=[Ad,ult,Fantasy,Mac]
&mappedCategoryID=[701,80,22]
&merchantID=36330&outputType=xml

Then will be disorder, if I use base64 it seems not work, if I use htmlentities it seems ,'s entity is ,. so how can I solve this?

Phoenix
  • 1,055
  • 1
  • 12
  • 27

1 Answers1

0

You can use this format:

?merchantCategoryName[]=Adult&
merchantCategoryName[]=Fantasy&
merchantCategoryName[]=Mac&
merchantID=36330&
outputType=xml

See this question for details

Community
  • 1
  • 1
Rodin Vasiliy
  • 573
  • 4
  • 7
  • But my receive point is JAVA, JAVA will parse this URL, is it work in JAVA? – Phoenix Mar 11 '15 at 09:49
  • And also, there is a chance that `merchantCategoryName` can be `Adu&lt` – Phoenix Mar 11 '15 at 09:51
  • I don't know about JAVA, you set tag `php` :) For escaping special characters in php you need to use [urlencode](http://php.net/manual/en/function.urlencode.php) and [urldecode](http://php.net/manual/en/function.urldecode.php) – Rodin Vasiliy Mar 11 '15 at 10:30
  • Yes it's PHP parse the url, JAVA is API provider – Phoenix Mar 12 '15 at 01:18
  • If I use `urlencode`, all commas will be encoded including the sepatator – Phoenix Mar 12 '15 at 01:19
  • You need to encode only data, not query string. For example: `foreach ($categories as $category) { $queryString .= "merchantCategoryName[]=" . urlencode($category) . "&" }` – Rodin Vasiliy Mar 12 '15 at 21:45