小编Gio*_*bbo的帖子

ASP.NET如何在Web API中读取多部分表单数据?

我将多部分表单数据发送到我的Web API,如下所示:

string example = "my string";
HttpContent stringContent = new StringContent(example);
HttpContent fileStreamContent = new StreamContent(stream);
using (var client = new HttpClient())
{
    using (var content = new MultipartFormDataContent())
    {
         content.Add(stringContent, "example", "example");
         content.Add(fileStreamContent, "stream", "stream");
         var uri = "http://localhost:58690/api/method";
         HttpResponseMessage response = await client.PostAsync(uri, content);
Run Code Online (Sandbox Code Playgroud)

这是Web API:

[HttpPost]
[Route("api/method")]
public async Task<HttpResponseMessage> Method()
    {
         // take contents and do something
    }
Run Code Online (Sandbox Code Playgroud)

如何在Web API中读取请求体中的字符串和流?

c# asp.net asp.net-web-api

12
推荐指数
3
解决办法
3万
查看次数

标签 统计

asp.net ×1

asp.net-web-api ×1

c# ×1