首页 > 解决方案 > 当在 Http.get 的 url 中发送 url 参数时,http GET 请求的 URL 被切断

问题描述

我遇到了一个问题,我的网址被切断了。我手动将我的网址放在一起,比如

this.http.get(apiUrl + 'endpoint?filter=' + encodeUri(JSON.stringify(params)).

这不起作用,所以我将其更改为像

this.http.get(apiUrl + 'endpoint', {params:filter}).

第一种方法的输出: http://mydomain/api/endpoint?filter=%7B%22where%22:%7B%22and%22:%5B%7B%22project_id%22:%220232%22%7D,%7B% 22楼%22:%22大楼%20

第二种方法的输出: http://mydomain/api/endpoint?filter=%7B%22where%22:%7B%22and%22:%5B%7B%22project_id%22:%220232%22%7D,%7B% 22楼%22:%22楼%20#1%7C楼%20#1%22%7D%5D%7D%7D

正如我们所见,第一种方法缺少很多字符。第二种方法的输出也是第一种方法的预期输出,而不是实际输出。谁能解释为什么会这样?

标签: angulartypescriptgetangular-http

解决方案


EncodeURIComponent将编码#, encodeURI 不会(并且用于获取整个 url 并在编码之前跳过第一部分)。用 # 传递它会提前终止它。


推荐阅读