下面的代码片段用于使用 restful API 调用我的 Web 服务。
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
String uri= "https://127.0.0.1:8443/cas-server-webapp-3.5.0/login";
WebResource resource = client.resource(URLEncoder.encode(uri));
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("username", "suresh");
queryParams.add("password", "suresh");
resource.queryParams(queryParams);
ClientResponse response = resource.type(
"application/x-www-form-urlencoded").get(ClientResponse.class);
String en = response.getEntity(String.class);
System.out.println(en);
并在运行上面的代码时得到这个异常
com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: URI is not absolute
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
我用谷歌搜索了很多文章,但没有找到我做错的地方。
旁注: cas-server-webapp-3.5.0
war 部署在我机器上的 Apache tomacat7
原文由 Suresh Atta 发布,翻译遵循 CC BY-SA 4.0 许可协议
一个绝对 URI 指定一个方案;一个不是绝对的 URI 被称为是相对的。
http://docs.oracle.com/javase/8/docs/api/java/net/URI.html
那么,也许您的 URLEncoder 没有像您期望的那样工作(https 位)?