我正在尝试向我的 API 发送图像和其他数据,例如 userId
。但是,这是两种不同的类型。
如何在 Postman 中发送图像和一些附加数据?
最佳答案
首先,创建一个接收 IFormData
和 string
标题的操作(如果需要,您可以将它们放在单独的类中):
[Route("api/[controller]")]
public class PostsController : ControllerBase
{
[HttpPost]
public async Task<IActionResult> Create(IFormFile image, string caption)
{
// Save image here
return Ok(caption);
}
}
使用 Postman,只需提交一个表单数据请求,如下所示:
关于rest - 如何使用 Postman 在 ASP.NET WebAPI 中发送图像和附加数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321862/