当我尝试执行请求时出现 IllegalArgumentException
在我的代码中,我在向服务器执行请求的行中捕获了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望您需要对参数进行 URL 编码(最有可能是
comment
变量)。编辑:您可以使用 java.net.URI 生成正确的查询。试试这个:
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:
为什么不预先构建字符串并记录它呢?然后你就可以看到85是什么字符了。如果日志是这样的话,我保证问题就存在。如果您无法弄清楚原因,请将生成的字符串与日志的其余部分一起发布。
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.