【发布时间】:2019-10-28 08:38:52
【问题描述】:
我的HttpClient 使用PostAsync 发送图像。
我不确定现在该做什么,因为这是我的第一个 REST Api,我还不能真正调整我在其他帖子中整理的内容。
希望大家能帮帮我,给我一个方向。
public async Task SendImage(string fullFileName, string fileName)
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://x.x.x.x");
var content = new StringContent(fullFileName, Encoding.UTF8, "image/jpg");
HttpResponseMessage response = await client.PostAsync($"/values/file/{fileName}", content);
}
我有几个关于 POST 功能的问题。
首先我可以用PostMan成功访问它,fileName是正确的。
如何读取图像数据并将其写入文件?
[HttpPost("file/{fileName}")]
public void Upload(string fileName)
{
Debug.Write(fileName);
}
编辑:
我设置了我的环境,现在我可以通过 Internet 将帖子发送到我发布的 Web Api。 在我的应用程序上什么也没有发生。 现在我只是想得到一些信息来处理,但我没有得到。
[HttpPost("file/{fileName}")]
public HttpResponseMessage Upload(UploadedFile fileName)
{
Debug.Write(fileName);
if (!ModelState.IsValid)
{
}
if (fileName == null)
{
}
string destinationPath = Path.Combine(@"C:\", fileName.FileFullName);
System.IO.File.WriteAllBytes(destinationPath, fileName.Data);
HttpResponseMessage rm = new HttpResponseMessage();
rm.StatusCode = HttpStatusCode.OK;
return rm;
}
【问题讨论】:
标签: c# asp.net-web-api