winform开发 本地文件夹上传到服务器 ,求代码
我要做的 是 上传图片的 但是一张张上传速度慢,也影响性能,所有打算 先吧图片放到本地的一个固定文件夹中,在直接上传这个文件夹。
我自己写的 代码 总是报 An exception occurred during a WebClient request. 错误
使用的是
/// 创建WebClient实例 --uriString 服务器路径 localFilePath本地路径
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
myWebClient.UploadFile(uriString,"PUT",localFilePath); ---------这里报的错
还有 一种
FileStream fs = new FileStream(localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1), FileMode.Open, FileAccess.Read); ------这里报错
BinaryReader r = new BinaryReader(fs);
byte[] postArray = r.ReadBytes((int)fs.Length);
Stream postStream = myWebClient.OpenWrite(uriString, "PUT");
if (postStream.CanWrite)
{
postStream.Write(postArray, 0, postArray.Length);
}
但是 都报错 ,望 那位同僚 帮帮忙 ,给给代码,说说错误的原因 ,怎么处理 等等 。