Her*_*rin 5 postman .net-core asp.net-core-webapi
我已经在 .Net Core 应用程序中创建了 api 项目。我还创建了接受HttpRequestMessage作为参数的方法。现在我尝试使用Postman包含文件作为主体参数来调用我的 api 方法,但我的 api 方法没有调用。
这是代码
[Route("api/[controller]")]
public class ValuesController : Controller
{
[HttpPost]
public HttpResponseMessage PostFiles()
{
HttpResponseMessage result = null;
var httpRequest = HttpContext.Request;
return result;
}}
Run Code Online (Sandbox Code Playgroud)
这是Postman请求数据
POST /api/values/PostFiles HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
主机:localhost:64226 内容类型:multipart/form-data;边界=----WebKitFormBoundary7MA4YWxkTrZu0gW 缓存控制:无缓存邮递员令牌:6adcc652-a4ab-3714-cc5e-770bd214ac7a
------WebKitFormBoundary7MA4YWxkTrZu0gW 内容处置:表单数据;名称=“数据”;文件名=“”内容类型:
------WebKitFormBoundary7MA4YWxkTrZu0gW--
这是我使用 postman 进行 api 调用的屏幕截图。
以文件作为参数的请求正文
我有什么遗漏的吗?
您能帮我使用 Postman 调用我的 Web api 并接受文件作为参数吗?
我觉得你的路线有问题。尝试这个 :
public class ValuesController : Controller
{
[Route("api/values/postfiles")]
[HttpPost]
public HttpResponseMessage PostFiles()
{
HttpResponseMessage result = null;
var files = Request.Form.Files;
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
然后尝试访问http://localhost:yourport/api/values/postfiles处的 API 。
将“yourport”替换为您的端口号。
如果文件可用,您将在“fileStream”中获取该文件。
| 归档时间: |
|
| 查看次数: |
9466 次 |
| 最近记录: |