javascript - 查询字符串仅向控制器发送一半 URL
问题描述
我有一个 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();
}
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
解决方案
查询字符串参数由&
符号分隔。如您所见,这正是您的 URL 被截断的地方。为了让控制器获得完整的 URL,您需要在作为查询参数传递之前对其进行编码:
encodeURIComponent(url)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
推荐阅读
- reactjs - 最终形式:从特定 FieldArray 中删除一个条目会从另一个 FieldArray 中删除一个条目
- html - 如何将弯曲方向固定为行
- excel - 从 MS Project 并使用 vba,在 excel 工作表上创建按钮,并通过运行 MS 项目宏启动它在 excel 中启动宏
- random - 随适用于该订单的每批货物退回随机订单
- c# - 解析 avro 模式会丢弃logicalType
- powershell - PowerShell Find-Package/Save-Package 需要私有 NuGet 存储库的凭据
- html - Text not staying in border?
- c++ - 从后台进程(独占模式)访问 wacom 数位板?
- python - 将十进制转换为二进制的函数:如何返回结果而不是打印结果?
- ios - 集合视图委托未在集合视图上的按钮单击和隐藏按钮上被调用