0

使用上传图像到网络服务时遇到问题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 参数为空,任何人都可以找出问题所在吗?

4

1 回答 1

0

你曾经在哪里data与价值联系在一起ImageBytes

作为替代方案,您是否尝试过使用UploadValues?参考在这里

在你的情况下,它会是这样的:

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 += ...
于 2013-04-15T11:14:37.013 回答