【发布时间】:2020-02-13 11:52:06
【问题描述】:
我正在尝试使用 curl 测试我的端点并获得 415:
curl -X POST "http://localhost:5001/api/countries/import" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer "$API_TOKEN \
--data @/D:/_countries.json
回复:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"0HLTFOME7T990:00000001"}
这是我的 .net 核心端点:
// POST api/countries/import
[HttpPost]
[Route("[action]")]
public async Task<IActionResult> Import(IFormFile file)
{
...
}
顺便说一句,我对邮递员中的这个端点没有任何问题,尽管它生成的代码对我不起作用(响应相同):
curl --location --request POST 'http://localhost:5001/api/countries/import' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {token here}' \
--form 'file=@/D:/_countries.json'
附:我正在使用 Windows 10 和 git bash 来运行脚本。
【问题讨论】:
标签: api curl post asp.net-core-webapi