【发布时间】:2023-04-05 11:07:01
【问题描述】:
我有一个接收图像和相关数据的 WebAPI 2.1 服务 (ASP.Net MVC 4)。 我需要从 WPF 应用程序发送此图像,但出现 404 not found 错误。
服务器端
[HttpPost]
[Route("api/StoreImage")]
public string StoreImage(string id, string tr, string image)
{
// Store image on server...
return "OK";
}
客户端
public bool SendData(decimal id, int time, byte[] image)
{
string url = "http://localhost:12345/api/StoreImage";
var wc = new WebClient();
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var parameters = new NameValueCollection()
{
{ "id", id.ToString() },
{ "tr", time.ToString() },
{ "image", Convert.ToBase64String(image) }
};
var res=wc.UploadValues(url, "POST", parameters);
return true;
}
url存在,我需要编码成json格式,但不知道怎么做。
感谢您的宝贵时间!
【问题讨论】:
-
确定属性路由已启用?我还建议使用模型 (DTO) 来管理数据
标签: c# wpf asp.net-web-api