簡體   English   中英

Spring Boot @RequestParam截斷了用?和's傳入的URL

[英]Spring Boot @RequestParam truncating URL's passed in with ?'s and #'s

我在使用Spring MVC @PathValue時遇到了類似的問題,但是沒有一個在線解決方案可以解決這個問題。

我目前正在開發一個應用程序,用戶將輸入一個URL,而@RequestParam似乎會截斷傳入的URL和#和s。

@RequestMapping(value = "/route/path", method = RequestMethod.GET, produces = "application/json")
public Value method(@RequestParam(value="url") String url, HttpServletRequest request) throws Exception {
    //execute code

現在,例如,如果有人要傳入localhost:8080 / route / path?url = https://css-tricks.com/hash-tag-links-padding/#article-header-id-0 ,查詢將被截斷to url = https://css-tricks.com/hash-tag-links-padding/

“&”似乎也發生了同樣的事情。 我在WebMvcConfigurerAdapter中嘗試了大量關於正則表達式,Bean配置和覆蓋configurePathMatch的解決方案。

其他人遇到過這個問題嗎? 如果是這樣,你找到了解決方法嗎? 謝謝!

您需要在傳入的URL上使用Percent Encoding

#%23

? %3F

使用encodeURIComponent對參數url進行編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM