【发布时间】:2021-08-05 02:08:01
【问题描述】:
当我向它发出请求时,我有以下 API,它返回不受支持的媒体类型我不知道是什么导致了这个问题。
[HttpPost("select/manager/{projectId}")]
public async Task<ActionResult<string>> SetProjectManager([FromBody] string name, string projectId)
{
var (isValid, username, password) = spManager.GetCredentials(HttpContext.Request.Headers["x-token"]);
if (!isValid || string.IsNullOrEmpty(name))
{
return BadRequest("Bad Key!");
}
var result = await spManager.SetProjectManager(username, password, name, projectId);
if (result.Success == true)
{
return Ok(new SubmissionResponse { Success = true, ErrorCode = null });
}
else
{
return NotFound(new SubmissionResponse { Success = false, ErrorCode = "Not Found!" });
}
}
我在标头中发送了一个令牌,但它没有显示在屏幕截图中:
【问题讨论】:
-
“HTTP 415 Unsupported Media Type 客户端错误响应代码表示服务器拒绝接受请求,因为负载格式不支持。” 415 Unsupported Media Type
-
需要将请求的内容类型头设置为JSON媒体类型。
-
尝试使用 {"name":"crisof"} 并选择 Json 而不是文本
标签: c# api asp.net-core .net-core