我有一个问题,当我调用带有许多 JSON 响应参数的 url 时,它会显示一个 URISyntaxError 但相同的 url 在所有浏览器上都可以正常工作。我无法理解出了什么问题?
The URL is: http://apibeta.highgearmedia.com/v1/vehicles/get-make-models.json?sort=mpg&filter=category&client-id=10030812&from=convertible&signature=QOwiWhG2T47KaQoyUztbag==
代码:
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(api_url));
HttpResponse response = client.execute(request);
InputStream ips = response.getEntity().getContent();
BufferedReader buf = new BufferedReader(new InputStreamReader(ips,
"UTF-8"));
StringBuilder sb = new StringBuilder();
String s;
while (true) {
s = buf.readLine();
if (s == null || s.length() == 0)
break;
sb.append(s);
}
buf.close();
ips.close();
return sb.toString();
错误:
05-10 23:03:45.326: W/System.err(2227): java.net.URISyntaxException: Illegal character in query at index 161: http://apibeta.highgearmedia.com/v1/vehicles/get-make-models.json?sort=mpg&filter=category&client-id=10030812&from=convertible&signature=QOwiWhG2T47KaQoyUztbag==
05-10 23:03:45.326: W/System.err(2227): at java.net.URI.validateQuery(URI.java:434)
05-10 23:03:45.326: W/System.err(2227): at java.net.URI.parseURI(URI.java:340)
05-10 23:03:45.335: W/System.err(2227): at java.net.URI.<init>(URI.java:72)
05-10 23:03:45.335: W/System.err(2227): at com.TCC.android.ResearchList.getJsonSring(ResearchList.java:3892)
05-10 23:03:45.335: W/System.err(2227): at com.TCC.android.ResearchList$67.run(ResearchList.java:4077)