"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 configuringHttpClient
.
On Android, you might want to use Uri.Builder
, like suggested in this other SO answer:
Uriuri=newUri.Builder()
.scheme("http")
.authority("example.com")
.path("someservlet")
.appendQueryParameter("param1", foo)
.appendQueryParameter("param2", bar)
.build();
HttpGetrequest=newHttpGet(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);HttpResponseresponse= defaultClient.execute(request);
Stringjson= 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"