调用Restful Webservice时,Uri不是绝对异常 [英] Uri not Absolute exception getting while calling Restful Webservice
问题描述
以下代码段用于使用restful API调用我的Web服务。
The below code snippet is using to call my web service using restful API.
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);
运行上述代码时出现此异常
And getting this exception while running the above code
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了很多文章并且没有得到我错误的地方。
I googled many articles and did'nt get where i am doing wrong .
附注: cas-server-webapp-3.5.0
war on deployment on我的机器在Apache tomacat7
Side note :cas-server-webapp-3.5.0
war deployed on my machine in Apache tomacat7
推荐答案
绝对URI指定一个方案;一个非绝对的URI被认为是相对的。
An absolute URI specifies a scheme; a URI that is not absolute is said to be relative.
http://docs.oracle.com/javase/8/docs/api/java/net/URI.html
那么,也许你的URLEncoder不能正常工作(https位)?
So, perhaps your URLEncoder isn't working as you're expecting (the https bit)?
URLEncoder.encode(uri)
这篇关于调用Restful Webservice时,Uri不是绝对异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!