调用http.get时编码

时间:2016-11-30 09:03:13

标签: azure angular

我正在使用Angular2中的continuationToken进行分页,问题是在调用http.get时,令牌未正确编码,我将收到错误请求错误。

let token:string;

let params: URLSearchParams = new URLSearchParams();
params.set('maxItemCount', maxItemCount.toString());
params.set('continuationToken', token);

let result = this._http.get(`myEndpoint/lists`, { search: params   }).map((response: Response) => {
  let res = <ResultObject>response.json();
  this.token = res.token;
  return res;
});

以下是调用http.get

后错误编码的标记的样子
https://apiaddress/lists?maxItemCount=5&continuationToken=%7B%22token%22:%22+RID:OsZtAJ7IPwCyAAAAAAAAAA==%23RT:1%23TRC:5%23RTD:lg4yMDE2LTExLTIxVDE2OjIzOjQ3Ljc5NjYwNTVa%23FPC:AgEAAAAUAEkAIBUVAFVVVVVVVVVVVVVFASoA%22,%22range%22:%7B%22min%22:%22%22,%22max%22:%22FF%22%7D%7D

以下是正确编码的令牌的显示方式

https://apiaddress/lists?maxItemCount=5&continuationToken=%7B%22token%22%3A%22%2BRID%3AOsZtAJ7IPwCyAAAAAAAAAA%3D%3D%23RT%3A1%23TRC%3A5%23RTD%3Alg4yMDE2LTExLTIxVDE2OjIzOjQ3Ljc5NjYwNTVa%23FPC%3AAgEAAAAUAEkAIBUVAFVVVVVVVVVVVVVFASoA%22%2C%22range%22%3A%7B%22min%22%3A%22%22%2C%22max%22%3A%22FF%22%7D%7D

我在尝试使用encodeUri和encodeUriComponent发送令牌之前尝试对该令牌进行编码,问题是http会对其进行重新编码,编码符号如%,这是之前编码的一部分。

我可以控制http.get如何对令牌进行编码吗?

0 个答案:

没有答案