亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AsyncRestTemplate '#' 在查詢參數中對編碼進行簽名

AsyncRestTemplate '#' 在查詢參數中對編碼進行簽名

開滿天機 2022-09-07 21:02:42
我正在使用AsyncRestTemplate從Springboot 1.5.2服務對Google Maps進行API調用。不幸的是,我的一些搜索字符串包含井號/主題標簽符號,并且在我的搜索參數中沒有正確編碼。我正在使用交換方法。#地址示例如下:05406, VT, BURLINGTON, 309 College St #10@Servicepublic class ExampleAsyncRestTemplate {    private AsyncRestTemplate asyncRestTemplate;    @Autowired    public ExampleAsyncRestTemplate() {        this.asyncRestTemplate = new AsyncRestTemplate();    }    public ListenableFuture<ResponseEntity<T>> getGeoCodedAddress() {         String googleUrl = "https://maps.googleapis.com/maps/api/geocode/json?address=05406, VT, BURLINGTON, 309 College St #10&key=some_key";         Map<String, String> uriVariables = new HashMap<>();         uriVariables.put("address", "05406, VT, BURLINGTON, 309 College St #10");         uriVariables.put("key", "some_key");         return asyncRestTemplate.exchange(googleUrl, HttpMethod.GET, new HttpEntity<>(), GoogleResponse.class, uriVariables);    }}生成的 URL 編碼為:https://maps.googleapis.com/maps/api/geocode/json?address=05406,%20VT,%20BURLINGTON,%20309%20College%20St%20#10&key=some_key請注意,當它應按照文檔進行編碼時,它仍在地址參數中。#%23深入調試器,似乎()后面的字符串被當作URL的片段。因此,為什么永遠不會被編碼。#10&key=some_key#是否有人能夠使用 AsyncRestTemplate 在您的查詢參數中提交符號?#我唯一能想到的是 替換為 ,這實際上有效,但感覺很笨拙/不理想。#number感謝您的幫助。
查看完整描述

1 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

請注意,這是一個模板,編碼的參數在其中進行插值。因此,您無法將實際參數作為 URL 的一部分提供。您需要將字符串更改為如下所示的模板googleUrl

final String googleUrl = "https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={key}";

這將返回正確的編碼:

https://maps.googleapis.com/maps/api/geocode/json?address=05406,%20VT,%20BURLINGTON,%20309%20College%20St%20%2310&key=some_key



查看完整回答
反對 回復 2022-09-07
  • 1 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號