【发布时间】:2020-03-10 05:57:39
【问题描述】:
我有一个带有如下控制器的 Web 服务:
[HttpGet]
[Customizing.RequestSizeLimit(1048576)] // 1 MB
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> ValidateTicketAsync([FromBody]KerberosTicketDto ticket)
{//code in here//}
Swagger 声明 Web 服务接受:
{
"ticket": "string"
}
从客户端,我得到一个 Kerberos 票并将其转换为字符串:
KerberosSecurityTokenProvider tokenProvider = new KerberosSecurityTokenProvider(ServiceServer, TokenImpersonationLevel.Identification);
KerberosRequestorSecurityToken token = tokenProvider.GetToken(TimeSpan.FromMinutes(1)) as KerberosRequestorSecurityToken;
...
tokenString = Convert.ToBase64String(token.GetRequest());
然后尝试将数据发送到网络服务器,并返回响应代码(即希望为 200):
WebClient webClient = new WebClient();
webClient.QueryString.Add("ticket", tokenString);
//webClient.QueryString.Add("spn", ServiceServer);
string result = webClient.DownloadString(urlTest);
然后调试窗口向我发送这个:
[10:40:21 DBG] Attempting to bind parameter 'ticket' of type 'Kerberos.TicketValidator.WebApi.Model.KerberosTicketDto' using the name 'ticket' in request data ...
[10:40:21 DBG] Rejected input formatter 'Microsoft.AspNetCore.Mvc.Formatters.JsonPatchInputFormatter' for content type 'null'.
[10:40:21 DBG] Rejected input formatter 'Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter' for content type 'null'
Web 服务获取的参数似乎不是它预期的类型。
谁能帮我把它转换成正确的类型?或者如何首先将其作为正确的类型发送?
谢谢!
【问题讨论】:
-
FromBody和HttpGet... 迷人 -
我没有编写api,我正在测试它。
-
swagger 显示了一些 json ...尝试像在 HTTP 请求的 body 中那样大摇大摆地发送 json ...只有一个问题 HTTP GET 不打算有 body
-
直截了当:
public async Task<IActionResult> ValidateTicketAsync([FromBody]KerberosTicketDto ticket)不在你的控制之下,你只应该测试它。对吗? -
如果你得到任何东西,应该是
POST请求FromBody
标签: c# web-services asp.net-core http-headers webclient