2012-03-29 17 views
0

在我的URI收到一個錯誤,同時發出請求

 uri.query = [id: "urn://salina/search/xplorer/XplorerApp",criteria:"{'includeNonGeotagged':'true','freetext':\{'text':" + "'" + "${searchString}" +"'}}",contentType:"rss20"] 

我有以下我得到一個錯誤說java.net.URISyntaxException:在查詢非法字符在指數94:https://pix.us.baesystems.com/search/query?id=urn://salina/search/xplorer/XplorerApp&criteria= {「includeNonGeotagged」:」 true','freetext':{'text':'test'}} & contentType = rss20

當我轉儲uri.toString()的值並將其放入瀏覽器時,它可以正常工作,所以我可以不知道這裏的問題是...

回答

0

你得到這個錯誤,因爲它e是URI中的未編碼字符。嘗試編碼或他們首先做一個URL出來的字符串:

def url = "https://pix.us.baesystems.com/search/query?id=urn://salina/search/xplorer/XplorerApp&criteria={'includeNonGeotagged':'true','freetext': {'text':'test'}}&contentType=rss20" 
URL url = new URL(url); 
URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null); 
println uri  

這將打印正確的URI:

https://pix.us.baesystems.com/search/query?id=urn://salina/search/xplorer/XplorerApp&criteria=%7B'includeNonGeotagged':'true','freetext':%7B'text':'test'%7D%7D&contentType=rss20 

也看到this answer的基本思想。

相關問題