angular - 当在 Http.get 的 url 中发送 url 参数时,http GET 请求的 URL 被切断
问题描述
我遇到了一个问题,我的网址被切断了。我手动将我的网址放在一起,比如
this.http.get(apiUrl + 'endpoint?filter=' + encodeUri(JSON.stringify(params))
.
这不起作用,所以我将其更改为像
this.http.get(apiUrl + 'endpoint', {params:filter})
.
正如我们所见,第一种方法缺少很多字符。第二种方法的输出也是第一种方法的预期输出,而不是实际输出。谁能解释为什么会这样?
解决方案
EncodeURIComponent
将编码#
, encodeURI 不会(并且用于获取整个 url 并在编码之前跳过第一部分)。用 # 传递它会提前终止它。
推荐阅读
- jquery - 未捕获的 TypeError:$.ajax(...).error 不是 rails 中的函数
- flutter - FormatException:Flutterinsta 包中的意外字符(在字符 1 处)
- python - 根据值从嵌套字典中检索键,其中键名未知
- php - 如何从图形 facebook API 获取匹配的记录?
- openssh - ssh "packet_write_wait: Connection to xxxx port 22: Broken pipe" -- 源代码在哪里?
- laravel - 我通过 Ajax 发表评论,但它不起作用
- java - java将字符串数据映射到python中的字典
- spring-boot - 如何在 azure devops 构建管道中填充 spring.active.profiles 值
- python - 堆化后的 Python 排序算法 Visualiser 堆排序错误(Tkinter)
- python - 使用另一个数据帧行中的多个值在熊猫数据帧中查找值