我們使用的是澤西客戶端2.21。我注意到,當我們將大括號(又名花括號)作爲參數值時,它不會得到正確的編碼。不僅如此,而且大括號內的任何內容都不會被編碼。對於我測試過的常規括號或其他不安全字符,這不是真的。在澤西客戶端2編碼大括號2
請看下面的例子。在這個例子中,我輸入了三個參數。一個只有空格的控制參數。一個花括號,另一個花括號。
public static void testJerseyEncoding() {
Client client = ClientBuilder.newClient();
String url = "http://foo.com/path";
Map<String, String> map = new HashMap<>();
map.put("paramWithCurly", " {with a space}");
map.put("paramWithOutCurly", "with a space");
map.put("paramWithBracket", "[with a space]");
WebTarget target = client.target(url);
for (Map.Entry<String, String> entry : map.entrySet()) {
target = target.queryParam(entry.getKey(), entry.getValue());
}
System.out.println(target.toString());
}
這裏是輸出:
JerseyWebTarget { http://foo.com/path?paramWithBracket=%5Bwith+a+space%5D¶mWithOutCurly=with+a+space¶mWithCurly=+{with a space} }
有什麼事與Jersey客戶端破還是我失去了一些東西?花括號應該被編碼爲「%7B」。
謝謝你發現它爲什麼不編碼大括號的奧祕。任何想法如何關閉這個花括號「功能」?對於球衣客戶端框架來說,處理花括號的方式看起來不太合適,花括號可編碼,因此可能會顯示在URI中。 –