BackgroundUploader抛出COMException:ERROR_INTERNET_LOGIN_FAILURE

时间:2012-05-08 17:39:30

标签: c# windows-8 windows-runtime .net-4.5

我尝试上传图片(由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的异常:0x80072EEF
  在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
  在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificat ion(任务任务)

0x80072EEF是ERROR_INTERNET_LOGIN_FAILURE:

  

“连接和登录FTP服务器的请求失败。”

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题。尽管这个问题有点陈旧,但在搜索答案时我被引导到这里。

我发现所描述的内容here让我感到满意。 基本上BackgroundDownloader在设置ServerCredentials时似乎失败了......