我在使用 webbrowser 时遇到问题,或者可能是 ftp。我正在上传一张图片,当我浏览网络浏览器时,它会向我显示旧照片,但我上传的图片会到达 ftp 并被覆盖。这是代码:
webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
webBrowser1.Navigate("www.google.com");
openFileDialog1.ShowDialog();
string filename = Path.GetFullPath(openFileDialog1.FileName);
FileInfo toUpload = new FileInfo(@"upload.jpg");
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://fingercube.co.cc/public_html/objimg/" + toUpload.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("username", "pass");
Stream ftpStream = request.GetRequestStream();
FileStream file = File.OpenRead(filename);
int lenght = 2;
byte[] buffer = new byte[lenght];
int bytesRead = 0;
do
{
bytesRead = file.Read(buffer, 0, lenght);
ftpStream.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
file.Close();
ftpStream.Close();
webBrowser1.Navigate("http://fingercube.co.cc/objimg/"+toUpload.Name);
它每次都向我显示旧照片,但每次都上传照片。:(