0

In my code I catch IllegalArgumentException (Illegal character in query at index 85) in line where I execute request to server. Work with was build as patter Command, another tasks completes correct but not this:

public CreateCommentTask(String barcodeId, String ball, String comment,
        String sign) {
    super(getApplicationUrl() + "?command=createComment" + "&barcodeId="
            + barcodeId + "&ball=" + ball + "&text=" + comment
            + "&sessionId=" + sign);
    // TODO Auto-generated constructor stub
}

So, I have only adres and some data in string formate. My app crash in this line:

HttpResponse response = client.execute(task.createRequest());

Do you have any ideas?

  • What are the strings you're passing to this method? The barcodeId, ball, comment, and sign – Geobits May 28 '11 at 15:02
  • see [this](http://stackoverflow.com/questions/3286067/url-encoding-in-android) and [this](http://stackoverflow.com/questions/3734844/how-to-url-encode-in-android) about url encoding in android. – bigstones May 28 '11 at 15:03
  • @Geobits, I pass this strings: String barcodeId = "4605246006340"; String ball = "10"; String comment = java.net.URLEncoder.encode("Mycomment", "UTF-8"); –  May 31 '11 at 11:01

2 Answers2

2

I expect you need to URL encode the parameters (most probably the comment variable).

EDIT: you can use java.net.URI to generate the proper query. Try this:

super(new URI(getApplicationUrl() + "?command=createComment" + "&barcodeId="
            + barcodeId + "&ball=" + ball + "&text=" + comment
            + "&sessionId=" + sign).toString());
Femi
  • 64,273
  • 8
  • 118
  • 148
  • this aproach didn't help me. Yes, I must use URLEncoder for comment and I do it - java.net.URLEncoder.encode("My comment", "UTF-8"), but it is not work. –  May 31 '11 at 10:59
  • The space between "my" and "comment" replaced on "+" but should be on "%20" –  May 31 '11 at 13:06
  • You don't want to use URLEncoder, in effect you want to use URI component encoding rules. Take a look at the class shown at http://stackoverflow.com/questions/607176/java-equivalent-to-javascripts-encodeuricomponent-that-produces-identical-output – Femi May 31 '11 at 13:22
0

Why don't you build the string beforehand and log it? Then you could see what character 85 is. I guarantee the problem is there if that's what the log says. If you can't figure out why, post the resulting string up, along with the rest of the log.

public CreateCommentTask(String barcodeId, String ball, String comment,
        String sign) {
    String query = getApplicationUrl() + "?command=createComment" + "&barcodeId="
            + barcodeId + "&ball=" + ball + "&text=" + comment
            + "&sessionId=" + sign;
    Log.d("HOLYCRAP", query);
    super(query);
}
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • Oh, sorry: I already solved issue with this exception but I have catched another ClientProtocolException: The server failed to respond with a valid HTTP response. I forget check my question as solved. –  May 31 '11 at 11:21
  • You should probably update your question so there's no more confusion. And you're going to want to put way more information that that, trust me – Geobits May 31 '11 at 11:28