在我的代码中,我在向服务器执行请求的行中捕获了 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/