Nic*_*ore 7 c# asp.net asp.net-web-api
在ASP.NET Web API的控制器中给出以下方法:
[HttpGet]
[ApiRoute("resource/{id}/end-point)]
public IHttpActionResult MethodName (int id, string clientTimeZone)
{
...
}
Run Code Online (Sandbox Code Playgroud)
每当我向http:// localhost:5684/api/v1/resource/1/end-point?client_timezone =%2B0500提交GET请求时,clientTimezone将作为%2B0500传递给clientTimeZone,并将编码后的"+"符号解析为空间角色.为什么ASP.NET不能从URI解码+?
在标题中,我有"ContentType = application/json"和一个承载令牌
我试图让"+0500"进入我的方法,但它变成了"0500"
小智 3
您在使用 api 时使用了Content-Typeof吗?application/x-www-form-urlencoded当在 URL 中使用“+”字符时,这会将其视为空格。
更多详细信息请参见: 何时将空格编码为加号 (+) 或 %20?
尝试更改Content-Type为application/json,看看参数绑定的行为是否符合预期。
| 归档时间: |
|
| 查看次数: |
298 次 |
| 最近记录: |