SkyDrive存在创建文件夹的问题

本文关键字:问题 文件夹 创建 存在 SkyDrive | 更新日期: 2023-09-27 18:27:50

我在这里读到了关于使用Live SDK在SkyDrive中创建文件夹的信息(这里没有提到"边界"参数),这是我的代码:

    WebRequest request = WebRequest.Create("https://apis.live.net/v5.0/folder.77e1a950546be643.77E1A950546BE643!202/files/");
    request.Method = "POST";
    string postData = "{name: '"My example folder'"}";
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    request.Headers.Add("Authorization", "Bearer " + access_token);
    request.ContentType = "application/json";
    request.ContentLength = byteArray.Length;

不确定我会得到什么400退货:

{"error":{"code":"request_header_invalid","message":"提供的标头"Content Type"缺少必需的参数"边界"。"}}

我做错了什么?我遗漏了什么吗?

谢谢你抽出时间!

SkyDrive存在创建文件夹的问题

尝试使用WindowsLiveClient,而不是从头开始创建自己的Web请求。我尝试了文档中的示例代码,它对我来说很好。这假设人们已经登录到Windows Live,会话存储在"会话"中。

if (session == null)
{
    infoTextBlock.Text = "You must sign in first.";
}
else
{
    Dictionary<string, object> folderData = new Dictionary<string, object>();
    folderData.Add("name", "A brand new folder");
    LiveConnectClient client = new LiveConnectClient(session);
    client.PostCompleted += 
        new EventHandler<LiveOperationCompletedEventArgs>(CreateFolder_Completed);
    client.PostAsync("me/skydrive", folderData);
}

然后还有一个函数将在操作完成时触发,用于捕获错误。

void CreateFolder_Completed(object sender, LiveOperationCompletedEventArgs e)
{
    if (e.Error == null)
    {
        infoTextBlock.Text = "Folder created.";
    }
    else
    {
        infoTextBlock.Text = "Error calling API: " + e.Error.ToString();
    }
}

根据w3的说法,当您发出HTTP206请求(一个多部分请求)时,就会出现错误。Windows Live的REST API文档也谈到了这一点,但不是在制作文件夹的上下文中,这表明拆分请求是在内置的LiveConnectClient中的某个位置完成的。