使用web client
将图片上传到网络服务时出现问题,
我的代码是--->
Uri uri = new Uri("http://localhost/Test/SaveImage");
string imageData = Convert.ToBase64String(data);
WebClient web = new WebClient();
web.UploadStringAsync(uri, "Post", imageData);
web.UploadStringCompleted += new UploadStringCompletedEventHandler(web_UploadStringCompleted);
在上面的代码中将图像转换为字节数组&然后到Base64String上传。
但是在接收端--->
[HttpPost]
public bool SaveImage(string ImageBytes) <---ImageBytes is Null
{
///// some code
}
ImageBytes参数变为空,有人能解决问题吗?
答案 0 :(得分:0)
您在哪里将data
与ImageBytes
的值相关联?
作为替代方案,您是否尝试过使用UploadValues
?引用为here。
在你的情况下,它就像是:
var uri = new Uri("http://localhost/Test/SaveImage");
var nameValueCollection = new NameValueCollection();
nameValueCollection.Add("ImageBytes", Convert.ToBase64String(data));
WebClient web = new WebClient();
web.UploadValuesAsync(uri, "Post", nameValueCollection);
web.OnUploadValuesCompleted += ...