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

2

3 Answers 3

5

You need to encode your url.

String query = URLEncoder.encode(myEditBox.getText.toString(), "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;
Sign up to request clarification or add additional context in comments.

Comments

0

Can you try

 httpclient.setRequestProperty("Accept-Charset","UTF-8");
 url="http://xxxxx/xxx/xxx&message="+URLEncoder.encode(myEditBox.getText.toString(), "UTF-8");

1 Comment

Oh... I posted just 25 seconds late :D
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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.