我正在从我的客户端(ASP.NET MVC)向 webapi 服务发送发布请求,但是,webapi 服务控制器需要一个Stream
始终为null
.
来自 ASP.NET MVC 应用程序的请求:
using(var client = new HttpClient())
{
Token token = GetToken();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.TokenType, token.AccessToken);
var content = new StreamContent(stream);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "keliaStream" };
var res = client.PostAsync(GetSdcUri(), content).Result;
}
WebApi 控制器:
// POST: api/Publication
[HttpPost]
[Route("whatever-route")]
[RequireHttps]
public System.Web.Mvc.ActionResult GenerateSDCFromTBox([FromBody]Stream keliaStream)
{
// whatever
}
keliaStream
始终为空,我错过了什么?