我有一个WebAPI 2.1服务(ASP.Net MVC 4),接收和图像及相关数据。 我需要从WPF应用程序发送此图像,但我得到404未找到错误。c#发送图像从WPF到WebAPI
服务器端
[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;
}
的网址存在,我的事情,我需要编码为JSON格式,但我不知道怎么办。
谢谢你的时间!
选中[在C#转换对象JSON(https://stackoverflow.com/questions/11345382/convert-object-to-json-string-in- c-sharp) –
已确定属性路由已启用?我也建议使用模型(DTO)来管理数据 – Nkosi