使用SkyDrive创建文件夹问题

nvc*_*nvn 2 c# liveconnect onedrive

我读过关于在SkyDrive中使用Live SDK创建的文件夹位置(在不提关于"边界"参数存在),这里是我的代码:

    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;
Run Code Online (Sandbox Code Playgroud)

不确定我得到400返回:

{"error":{"code":"request_header_invalid","message":"提供的标题'Content-Type'缺少必需参数'boundary'." }}

我做错了什么?我错过了什么吗?

谢谢你的时间!

Khe*_*ter 5

尝试使用WindowsLiveClient,而不是从头开始创建自己的webrequest.我在文档上尝试了示例代码,它对我很好.这假定人们已经登录到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);
}
Run Code Online (Sandbox Code Playgroud)

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

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

根据w3,当您发出HTTP206请求(多部分请求)时,会出现错误.Windows Live的REST API文档也讨论了这一点,但不是在创建文件夹的上下文中,这表明拆分请求是在内置的LiveConnectClient中的某个地方完成的.