我有一個 URL,我試圖將它作為查詢字串傳遞給控制器??。但是當我這樣做時,我只得到一半的 URL。但是,console.log 會列印整個 URL。
export async function sendNotification(PlanId: string, URL: string) {
console.log("Service URL : - ", URL);
let url = HttpClient.buildUrl(`api/smsNotification/${PlanId}?URL=${URL}`);
return await HttpClient.get(url);
}
[HttpGet("Notification/{PlanId}")]
[ValidateModelState]
public async Task<IActionResult> SendNotification(Guid PlanId, string URL)
{
return NoContent();
}
控制臺日志列印此 URL
https://chats.landbot.io/v3/index.html?name=Sys Admin&planid=a7f8&environment=dev&stack=dev
但是在控制器上,我得到了這個 URL
https://chats.landbot.io/v3/index.html?name=Sys Admin
uj5u.com熱心網友回復:
查詢字串引數用&符號分隔。如您所見,這正是您的 URL 被截斷的地方。為了讓控制器獲得完整的 URL,您需要在作為查詢引數傳遞之前對其進行編碼:
encodeURIComponent(url)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/321734.html
標籤:javascript asp.net-mvc asp.net核心 .net核心
