我正在尝试将文件上传到 ftp 服务器,我正在使用以下代码:
Uri uri;
if (!Uri.TryCreate(serverAddressField.Text.Trim(), UriKind.Absolute, out uri))
{
rootPage.NotifyUser("Invalid URI.", NotifyType.ErrorMessage);
return;
}
// Verify that we are currently not snapped, or that we can unsnap to open the picker.
if (ApplicationView.Value == ApplicationViewState.Snapped && !ApplicationView.TryUnsnap())
{
rootPage.NotifyUser("File picker cannot be opened in snapped mode. Please unsnap first.", NotifyType.ErrorMessage);
return;
}
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
StorageFile file = await picker.PickSingleFileAsync();
if (file == null)
{
rootPage.NotifyUser("No file selected.", NotifyType.ErrorMessage);
return;
}
PasswordCredential pw = new PasswordCredential();
pw.Password = "pass";
pw.UserName = "username";
BackgroundUploader uploader = new BackgroundUploader();
uploader.ServerCredential = pw;
uploader.Method = "POST";
uploader.SetRequestHeader("Filename", file.Name);
UploadOperation upload = uploader.CreateUpload(uri, file);
Log(String.Format("Uploading {0} to {1}, {2}", file.Name, uri.AbsoluteUri, upload.Guid));
// Attach progress and completion handlers.
await HandleUploadAsync(upload, true);
但它在这里向我发送了这个异常: UploadOperation upload = uploader.CreateUpload(uri, file); “在 Microsoft.Samples.Networking.BackgroundTransfer.exe 中发生了“System.ArgumentException”类型的异常,但未在用户代码中处理
WinRT 信息:'uri':仅支持 'http' 和 'https' 方案上传内容。”