我尝试上传一张图片(由 FileOpenPicker 选择),但它不起作用。
我的代码:
var openpicker = new FileOpenPicker();
openpicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openpicker.FileTypeFilter.Add(".jpg");
openpicker.FileTypeFilter.Add(".png");
var file = await openpicker.PickSingleFileAsync();
var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
PasswordCredential pw = new PasswordCredential();
pw.Password = "mypw";
pw.UserName = "user";
uploader.ServerCredential = pw;
uploader.Method = "POST";
var uri = new Uri("ftp://myaddress/Directory/");
var str = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
await uploader.SetSourceStreamAsync(str);
uploader.SetRequestHeader("Filename", "image2.jpg");
var upload = uploader.CreateUpload(uri);
var result = (await upload.StartAsync()).GetResponseInformation().StatusCode;
我在最后一行得到以下异常:
System.Runtime.InteropServices.COMException (0x80072EEF):来自 HRESULT 的异常:
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
处的 0x80072EEF System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
0x80072EEF 是 ERROR_INTERNET_LOGIN_FAILURE:
“连接和登录 FTP 服务器的请求失败。”
任何想法我做错了什么?