」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > MVC Web API 2請求參數中如何處理點字符(.)?

MVC Web API 2請求參數中如何處理點字符(.)?

發佈於2025-04-14
瀏覽:109

How to Handle Dot Characters (.) in MVC Web API 2 Request Parameters?
在MVC Web API中地址DOT字符2請求參數

http://somedomain.com/api/people/staff.333311

,但是,他們遇到了404個錯誤。之所以發生這種情況,是因為Web API的默認路由旨在將URL路徑中的段識別為控制器和操作名稱,並且隨後具有可選參數。 The dot character in the request URL is causing ambiguity as it is parsed either as a part of the action name or a query parameter.

Proposed Solution

To resolve this issue, the user can ensure that the request parameter in question is not part of a URL path segment it can't be mistaken for a controller or action name.實現這一目標的一種方法是在URL中添加尾隨的斜線,例如:

http://somedomain.com/api/people/people/staff.333311/
http://somedomain.com/api/people/staff.33311

通過實現此解決方案,用戶可以在參數中使用dot字符來處理請求,同時維護一致且不謹慎的請求格式。

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3