使用以下网址我收到了错误消息:
java.lang.IllegalArgumentException: Illegal character in path at index 47: http://safetracker-threetinker.rhcloud.com/api/{userid}/locations?lat={latitude}&lng={longitude}.
URL:
URL=http://safetracker-threetinker.rhcloud.com/api/{userid}/locations?lat={latitude}&lng={longitude}
如何解决错误。我对URL编码知之甚少。请帮我找到解决方案。
答案 0 :(得分:0)
问题实际上是它正在寻找长/整数值并且你传递一个ALTERING
只是放一个{
以便它将被变量指向的实际值替换
http://safetracker-threetinker.rhcloud.com/api/1/locations?lat=5&lng=5
您的地址就像这样
$
应该是这样的
URL=http://safetracker-threetinker.rhcloud.com/api/{userid}/locations?lat={latitude}&lng={longitude}
答案 1 :(得分:0)
我们不能在URL中使用某些特殊字符,因此我们必须用其编码形式替换这些特殊字符。 用以下网址替换您的网址
URL=http://safetracker-threetinker.rhcloud.com/api/%7Buserid%7D/locations?lat=%7Blatitude%7D&lng=%7Blongitude%7D
愿这对你有所帮助。
答案 2 :(得分:0)
URLEncoder应该是要走的路。您只需要记住只编码单个查询字符串参数名称和/或值,而不是整个URL,肯定不是查询字符串参数分隔符字符&也不是参数名称 - 值分隔符=。
String q = "replace_with user_id/locations?lat=replace with latitude&lng=replace with longitude";
String url = "http://safetracker-threetinker.rhcloud.com/api/=" + URLEncoder.encode(q, "UTF-8");