【发布时间】:2020-11-12 21:16:22
【问题描述】:
我在从我的 Angular 前端到我的 .net API 的 POST 请求中遇到了一些麻烦。
这是前面的代码:
[...]
this.uploadFile(JSON.stringify(jsonobject));
}
uploadFile(file)
{
this.files.push(file);
this.uploadService.uploadjsonresponse(file, "JsonFilterResponse").subscribe();
}
和发布请求:
public uploadjsonresponse(file, apiname) {
return this.httpClient.post(this.SERVER_URL + apiname, file);
}
最后是 .net 代码:
[HttpPost]
[Route("api/JsonFilterResponse")]
[RequestSizeLimit(4_000_000_000)]
[Microsoft.AspNetCore.Cors.EnableCors]
public IActionResult JsonFilterResponse([FromBody] string jsonresult)
{
try
{
if (jsonresult != null)
{
Response.Body.Flush(); // http response
return Ok(); // server response
}
else
return NotFound();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return StatusCode(500, "Internal server error");
}
}
Json 对象是正确的(在控制台上检查),API 地址也是正确的。 API 正在返回一个我似乎无法动摇的 415。任何建议将不胜感激!
【问题讨论】:
-
什么是jsonobject?怎么样?
-
当我记录前面发送的数据时,它看起来像这样:{"xxxxxx/xxxxxxxxx/xxxxxxxx":{"0":"*"}}。
标签: .net angular api http-status-code-415