Angular 7+ 如何防止查询参数特殊字符转换为十六进制代码?

Jes*_*sse 1 angular

示例端点:

https://localhost:4200/test/index.html?param1=username%2passw0rd&baseApi=https://someOtherService/APIBase.jsp?INT/
Run Code Online (Sandbox Code Playgroud)

当我点击上面的端点时。我的网址被转换成这个...

https://localhost:4200/test/index.html?param1=username%2passw0rd&baseApi=https:%2F%2FsomeOtherService%2FAPIBase.jsp
Run Code Online (Sandbox Code Playgroud)

正如您在 baseApi 参数中所看到的,“/”被转换为“%2F”并且值“?INT/”也被删除了。

如何防止 URL 转换“/”并为第二个参数“baseApi”中的值保留“?INT/”值。

参考

Aus*_*nch 10

你没有。如果允许,它将破坏互联网。

更多细节:

  1. 您可以在后端 API 上使用 URL 解码将 URL 转换回标准文本。
  2. 永远不要在 URL 中传递密码。这实际上是您可以做的最不安全的事情之一。

第 1 点:情况并非总是如此,许多 API 框架会自动解码查询字符串。

如果您需要传递完整的 URL,请确保它已正确编码:

console.log("https://localhost:4200/test/index.html?" + encodeURIComponent("param1=username%2passw0rd&baseApi=https://someOtherService/APIBase.jsp?INT/"));
Run Code Online (Sandbox Code Playgroud)

https://localhost:4200/test/index.html?param1%3Dusername%252passw0rd%26baseApi%3Dhttps%3A%2F%2FsomeOtherService%2FAPIBase.jsp%3FINT%2F