当我尝试执行请求时出现 IllegalArgumentException

发布于 2024-11-10 09:29:34 字数 609 浏览 0 评论 0原文

在我的代码中,我在向服务器执行请求的行中捕获了 IllegalArgumentException(索引 85 处查询中的非法字符)。使用的是构建为 patter 命令,另一个任务正确完成,但不是这样:

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
}

所以,我只有地址和字符串格式的一些数据。我的应用程序在这行崩溃:

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

你有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗化ㄋ丶相逢 2024-11-17 09:29:35

我希望您需要对参数进行 URL 编码(最有可能是 comment 变量)。

编辑:您可以使用 java.net.URI 生成正确的查询。试试这个:

super(new URI(getApplicationUrl() + "?command=createComment" + "&barcodeId="
            + barcodeId + "&ball=" + ball + "&text=" + comment
            + "&sessionId=" + sign).toString());

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());
忱杏 2024-11-17 09:29:35

为什么不预先构建字符串并记录它呢?然后你就可以看到85是什么字符了。如果日志是这样的话,我保证问题就存在。如果您无法弄清楚原因,请将生成的字符串与日志的其余部分一起发布。

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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文