gpt4 book ai didi

c# - ASP.NET Web API 解码中的参数绑定(bind) + (%2B) As Space

转载 作者:太空狗 更新时间:2023-10-29 20:35:52 26 4
gpt4 key购买 nike

给定 ASP.NET Web API Controller 中的以下方法:

[HttpGet]
[ApiRoute("resource/{id}/end-point)]
public IHttpActionResult MethodName (int id, string clientTimeZone)
{
...
}

每当我向 http://localhost:5684/api/v1/resource/1/end-point?client_timezone=%2B0500 提交 GET 请求时clientTimezone 作为 %2B0500 传递给 clientTimeZone,并将编码的“+”符号解析为空格字符。为什么 ASP.NET 不能从 URI 中解码 +?

在 header 中我有“ContentType = application/json”和一个不记名 token

我试图将“+0500”放入我的方法中,但它正在变成“0500”

最佳答案

您在使用 API 时是否使用 application/x-www-form-urlencodedContent-Type?当在您的 URL 中使用时,这会将“+”字符视为空格。

更多细节在这里: When to encode space to plus (+) or %20?

尝试将您的 Content-Type 更改为 application/json 并查看参数绑定(bind)的行为是否符合预期。

关于c# - ASP.NET Web API 解码中的参数绑定(bind) + (%2B) As Space,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49820501/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com