我在我的 wp7 应用程序的客户端将图像转换为字节数组,然后将其发送到 Web 服务(服务器),代码如下所示--->
客户端
private void SendImage(byte[] data, long UserID)
{
Uri uri = new Uri("some uri");
IDictionary<string, object> bytesToSend = new Dictionary<string, object>();
bytesToSend.Add("ImageBytes", Convert.ToBase64String(data));
PostClient post = new PostClient(bytesToSend);
post.DownloadStringAsync(uri);
}
服务器端
[HttpPost]
public bool SaveImage(object ImageBytes, Int64 UserID = 1)
{
string ImgStr = ((string[])(ImageBytes))[0];
byte[] ImgBytes = Convert.FromBase64String(ImgStr); ///<----///ERROR
Image ItemImage;
using (MemoryStream ms = new MemoryStream(ImgBytes))
{
ItemImage = Image.FromStream(ms);
}
PostUserItems(ItemImage);
return true;
}
但在接收端发生错误
基数 64 字符数组的长度无效