Need to pass get parameter without value and without “=” symbol to utilize external API. The URL is
http://example.com/Service/v1/service.ashx?methodName&name=val&blablabla
As you could see first parameter is the name of the method (methodName) to be called on the server and it does not have any value nor “=”.
I want to form parameters in “right” way but at the moment forming them like below:
List<NameValuePair> params = new LinkedList<NameValuePair>();
params.add(new BasicNameValuePair("name", "val"));
params.add(new BasicNameValuePair("name1", "val1"));
String paramString = URLEncodedUtils.format(params, "utf-8");
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(getEndpointUrl() + "?methodName&" + paramString);
The problem is in last line where concatenation is used (instead of regular conversion of params). Adding “methodName” as name to params and null as value gives “methodName=” in resulting URL. Server does not understand such notation.
I think you’d be better off forming the URL manually. We use HttpGet methods extensively, and when we construct URL strings, we do so manually to ensure parameter ‘correctness’. We then use URIUtil from the HttpClient project to encode the query string: