我有一個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