我试图在我的一个参数中发出一个带有冒号的 get,但它失败了,unknownHostException
这是我的代码:
String id = "{\"ID\":\"John Doe\"}";
String encodedID = URLEncoder.encode(id, "UTF-8").replace("+", "%20");
endpoint="https://127.0.0.1/getResourceNameToUse?id=" + encodedID;
HttpResponse response = new HttpResponse();
HttpGet httpget = new HttpGet(endpoint);
response = httpclient.execute(httpget, new RESTResponseHandler());
我收到以下错误:
java.net.UnknownHostException: 127.0.0.1/getResourceNameToUse?id={"ID"
所以看起来冒号正在破坏获取请求。有没有办法来解决这个问题?为什么编码它不能解决问题?我的编码 id 如下所示:
%7B%22ID%22%3A%22约翰%20Doe%22%7D