乌里不是绝对的例外获得同时呼吁RESTful Web服务(Uri not Absolute exce

2019-08-16 22:20发布

下面的代码片段使用使用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)

我GOOGLE了许多文章和did'nt得到我在哪里做错了。

附注: cas-server-webapp-3.5.0战争阿帕奇tomacat7部署了我的机器上

Answer 1:

绝对URI指定了一个方案; 一个URI,也不是绝对的,据说是相对的。

http://docs.oracle.com/javase/8/docs/api/java/net/URI.html

所以,也许你的URLEncoder的工作不为你期待(https的位)?

    URLEncoder.encode(uri) 


Answer 2:

The problem is likely that you are calling URLEncoder.encode() on something that already is a URI.



文章来源: Uri not Absolute exception getting while calling Restful Webservice