Question

I have read about creating folder in SkyDrive with Live SDK here (the don't mention about 'boundary' parameter there), here is my code:

    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;

And not sure whay I get a 400 returned:

{ "error": { "code": "request_header_invalid", "message": "The provided header 'Content-Type' is missing a required parameter 'boundary'." } }

What I am doing wrong? Do i missing anything?

Thanks for your time!

Was it helpful?

Solution

Try using the WindowsLiveClient rather than making your own webrequest from scratch. I tried the example code on the documentation and it's worked fine with me. This assumes that people are already signed in to Windows Live, with the session stored in "session".

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);
}

And then there's a function to be triggered when the operation completes, for catching errors.

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

According to w3, the error you got occurs when you're making an HTTP206 request, a multipart request. Windows Live's REST API documentation also talks about this, but not in the context of making folders, which suggests that the split request is done somewhere in the built-in LiveConnectClient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top