我需要POST
来自 WinRT 应用程序的创建请求,该请求应包含StorageFile
. 我需要完全按照这样的方式执行此操作:在正文中发布带有文件的请求。可能吗?我知道HttpClient.PostAsync(..)
,但我不能放入StorageFile
请求正文中。我想发送mp3
文件到Web Api
在服务器端,我得到这样的文件:
[System.Web.Http.HttpPost]
public HttpResponseMessage UploadRecord([FromUri]string filename)
{
HttpResponseMessage result = null;
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
var filePath = HttpContext.Current.Server.MapPath("~/Audio/" + filename + ".mp3");
postedFile.SaveAs(filePath);
}
result = Request.CreateResponse(HttpStatusCode.Created);
}
else
{
result = Request.CreateResponse(HttpStatusCode.BadRequest);
}
return result;
}