【问题标题】:Creating folders issue with SkyDriveSkyDrive 创建文件夹问题
【发布时间】:2012-03-15 14:57:18
【问题描述】:

我已阅读有关使用 Live SDK here 在 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": "The 提供的标头“Content-Type”缺少必需的参数 '边界'。” } }

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

感谢您的宝贵时间!

【问题讨论】:

标签: c# onedrive liveconnect


【解决方案1】:

尝试使用 WindowsLiveClient,而不是从头开始制作您自己的网络请求。我尝试了文档上的示例代码,它对我来说效果很好。这假定人们已经登录到 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 request(一个多部分请求)时会发生错误。 Windows Live 的REST API documentation 也谈到了这一点,但不是在制作文件夹的上下文中,这表明拆分请求是在内置 LiveConnectClient 的某个地方完成的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    相关资源
    最近更新 更多