1

I am trying to send a query url

String url = String.format(
   "http://xxxxx/xxx/xxx&message=%s",myEditBox.getText.toString());
// Create a new HttpClient and Post Header
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httpclient.getCookieStore().addCookie(cooki);
try {
   ResponseHandler<String> responseHandler = new BasicResponseHandler();
   httpclient.getParams().setParameter("http.connection-manager.timeout", 15000);
   String response = httpclient.execute(httppost, responseHandler);

gives me error, illegal character at query. That's white space probably. How to deal with this issue?

Best Regards

Aubin
  • 14,617
  • 9
  • 61
  • 84
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193
  • http://stackoverflow.com/questions/3286067/url-encoding-in-android – Matthieu Nov 01 '12 at 08:21
  • You can use URLEncoder for that Try these http://stackoverflow.com/questions/3286067/url-encoding-in-android http://stackoverflow.com/questions/3734844/how-to-url-encode-in-android – Amit Hooda Nov 01 '12 at 08:22

3 Answers3

5

You need to encode your url.

String query = URLEncoder.encode(myEditBox.getText.toString(), "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;
Chirag
  • 56,621
  • 29
  • 151
  • 198
0

Can you try

 httpclient.setRequestProperty("Accept-Charset","UTF-8");
 url="http://xxxxx/xxx/xxx&message="+URLEncoder.encode(myEditBox.getText.toString(), "UTF-8");
anishsane
  • 20,270
  • 5
  • 40
  • 73
0

Try .trim() while get value from edittext. May be whitespace come from edittext and also use "utf-8".

see below code.

String value = URLEncoder.encode(myEditBox.getText.toString().trim(), "utf-8");
String url = "http://xxxxx/xxx/xxx&message=%s" + value;
Arvind Kanjariya
  • 2,089
  • 1
  • 18
  • 23