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

标签 java android illegalargumentexception

在我的代码中,我在向服务器执行请求的行中捕获了 IllegalArgumentException(索引 85 处查询中的非法字符)。使用 was build as 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());

你有什么想法吗?

最佳答案

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

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

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

关于java - 当我尝试执行请求时出现 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6162300/

相关文章:

java - 第谷跳过测试

android - 保护 Dropbox 访问 token 的安全

Java 分数计算器 - 通过 try/catch 除以零方法

java - 这个 IllegalArgumentException 的可能原因是什么?

java - 当我旋转模拟器时,如何阻止我的 Activity 被破坏?

java - 实现一个链表栈和队列,不知道自己设置的代码是否足够高效

Android 应用程序使用 getWritableDatabase 崩溃

android - 计算库(Jar/AAR)中的方法数

java - 何时抛出 IllegalStateException 与 IllegalArgumentException?

java - 如何在 php 脚本中执行 Java 程序?