jra*_*ose 5 javascript http urlencode angular angular7
我正在尝试在 Angular 7 中对查询参数值进行编码。但是当我的查询参数值包含任何特殊字符时,我得到 400 Bad Request 状态代码
失败的请求 URL: http://localhost/api/67/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE%20AGE
但是,当我的查询参数值不包含任何特殊字符时,我得到 200 OK 状态代码。
请求成功地址: http://localhost/api/67/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE
预期的请求 url 必须像 http://localhost/cardvalues?parentcardvalues=VALUE1&parentcardvalues=VALUE2
下面是我的代码,
parentcardvalues=["STONE","STONE AGE"]
let myparams = new HttpParams();
if(parentcardvalues.length != 0)
parentcardvalues.forEach((value) => {
myparams = myparams.append( 'parentcardvalues', encodeURIComponent(value) );
});
this.http.get(this.baseUrl + 'api/67/cardvalues', {params: myparams});
Run Code Online (Sandbox Code Playgroud)
Swagger 规范是,
卷曲
curl -X GET "http://localhost/api/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE%20AGE" -H "accept: application/json"
Run Code Online (Sandbox Code Playgroud)
请求网址
http://localhost/api/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE%20AGE
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法解码您的参数:
decodeURIComponent(encodedURI_string)
Run Code Online (Sandbox Code Playgroud)
更多信息请点击此处
| 归档时间: |
|
| 查看次数: |
12076 次 |
| 最近记录: |