winform webclient 上传报错 System.Net.WebException: 远程服务器返回错误: (403) 已禁止
stringudfString;WebClientmyWebClient=newWebClient();myWebClient.Credentials=Credentia...
string udfString;
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
FileStream ufs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
BinaryReader ufr = new BinaryReader(ufs);
//远程服务器地址
udfString = "http://xxx.xxx.xxx.com/aaa/" + file.Name;
try
{
byte[] uploadArray = ufr.ReadBytes((int)ufs.Length);
Stream uploadStream = myWebClient.OpenWrite(udfString, "PUT");
if (uploadStream.CanWrite)
{
uploadStream.Write(uploadArray, 0, uploadArray.Length);
}
else
{
MessageBox.Show("文件目前不可写!");
}
uploadStream.Flush();
uploadStream.Close(); 展开
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
FileStream ufs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
BinaryReader ufr = new BinaryReader(ufs);
//远程服务器地址
udfString = "http://xxx.xxx.xxx.com/aaa/" + file.Name;
try
{
byte[] uploadArray = ufr.ReadBytes((int)ufs.Length);
Stream uploadStream = myWebClient.OpenWrite(udfString, "PUT");
if (uploadStream.CanWrite)
{
uploadStream.Write(uploadArray, 0, uploadArray.Length);
}
else
{
MessageBox.Show("文件目前不可写!");
}
uploadStream.Flush();
uploadStream.Close(); 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询