angular - Angular 将所有 /(反斜杠)替换为 %5C
问题描述
我正在我的 PC 上构建一个 REST 服务。当我发送请求 url 时,浏览器(我正在使用 chrome)将所有 '/' 转换为 %5C。它适用于某些情况。但大多数情况下 url 都发生了变化。错误:对于 url:http://localhost:3028/controller/addFile?file=C:/Users/Acer/Desktop/Dhana/d/s.txt
GET http://localhost:3028/controller/addFile?file=C:%5CUsers%5CAcer%5CDesktop%5CDhana%5Cd%5Cs.txt 500
我的 component.ts 代码是:
filePath = 'http://localhost:3028/controller/addFile';
addFile(file) : void{
this.params = new HttpParams();
file = this.directory + '\\' + file;
this.params = this.params.append('file', file);
this.http.get(this.filePath, { params: this.params }).subscribe((data: any) => {
});
}
解决方案
URL 只能使用 ASCII 字符集通过 Internet 发送。
当它包含 ASCII 集之外的字符时,必须将 URL 转换为有效的 ASCII 格式。阅读时必须对 URL 参数进行编码和解码。
推荐阅读
- .htaccess - 重定向 404 [未找到] 错误到主页和在重定向到主页之前,告诉搜索引擎 404 页面已消失 [410] 使用 .htaccess
- python - 如何在python中的commands.getstatusoutput上传递变量
- asp.net - 如何将网格视图导出到光盘上的 csv 文件?
- excel - 在 Excel VBA Sub 中读取变量 DAO.QueryDef
- c# - 我无法从 uwp App 中的 ID3 标签读取信息
- hadoop - 多个元存储服务器的 Apache Hive 多个 hive-site.xml
- html - 为什么我的复选框没有正确对齐?百里香叶
- c# - 在并行处理循环中使用单线程对象列表
- postgresql - setval 和 alter sequence restart 命令之间的区别
- mysql - Mysql order by 从 1,000,000 行开始很慢,我们有近 300,000 个搜索结果