我收到一个错误:
W/System.err(32720): java.lang.IllegalArgumentException: Illegal character in query at index 89: https://api.mongolab.com/api/1/databases/activity_recognition/collections/entropy_data?f={%20mean0%22:%201}&apiKey=myApiKey
String apiURI = "https://api.mongolab.com/api/1/databases/activity_recognition/collections/entropy_data?f={%22mean0%22:%201}&apiKey=myApiKey";
- 当我将此 URI 粘贴到浏览器中时,它工作正常。
- 当我粘贴到浏览器中,打开它,然后将 URI 复制回我的代码中,它没有帮助。
- 索引 89 是 { - 这怎么是非法字符?
我试过这样做 - 用 %7B: 替换大括号:但这没有帮助
https://api.mongolab.com/api/1/databases/activity_recognition/collections/entropy_data?f=%7B"mean0":%201%7D&apiKey=myApiKey
任何人?
编辑:
String query = "https://api.mongolab.com/api/1/databases/activity_recognition/collections/entropy_data?f={\""+arrayName+"\":%201}&apiKey=myApiKey";
try {
query = URLEncoder.encode(query, "utf-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String apiURI = query;
没有帮助。现在我得到:
05-23 22:13:21.855: E/SendMail(12428): Target host must not be null, or set in parameters. scheme=null, host=null, path=https://api.mongolab.com/api/1/databases/activity_recognition/collections/entropy_data?f={"mean0":%201}&apiKey=myAPI
如果我在查询声明中将 %20 更改为空格,那么我得到:
05-23 22:14:51.435: E/SendMail(13164): Target host must not be null, or set in parameters. scheme=null, host=null, path=https://api.mongolab.com/api/1/databases/activity_recognition/collections/entropy_data?f={"mean0":+1}&apiKey=myAPI
另外,如果我不使用中间的arrayName字符串而直接使用浏览器中的字符串,效果是一样的!