"Illegal Characters" In URL For HttpGet In Android Get Double-encoded
I am trying to find a solution to this the whole evening now... I write an app which requests data from a web server. The Server answers in JSON format. Everything works well excep
Solution 1:
Update: Sorry, HttpParams
isn't meant for request parameters but for configuring HttpClient
.
On Android, you might want to use Uri.Builder
, like suggested in this other SO answer:
Uri uri = new Uri.Builder()
.scheme("http")
.authority("example.com")
.path("someservlet")
.appendQueryParameter("param1", foo)
.appendQueryParameter("param2", bar)
.build();
HttpGet request = new HttpGet(uri.toString());
// This looks very tempting but does NOT set request parameters
// but just HttpClient configuration parameters:
// HttpParams params = new BasicHttpParams();
// params.setParameter("q", query);
// request.setParams(params);
HttpResponse response = defaultClient.execute(request);
String json = EntityUtils.toString(response.getEntity());
Outside of Android, your best bet is building the query string manually (with all the encoding hassles) or finding something similar to Android's Uri.Builder
.
Post a Comment for ""Illegal Characters" In URL For HttpGet In Android Get Double-encoded"