Url 当 url 参数在 url 中发送 Http.get 时,http GET 请求被切断

Url for http GET request is being cut off when url params sent in url for Http.get

我遇到了一个问题,我的 url 被切断了。我手动将我的 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%22floor%22:%22Building%20

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

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

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