Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Api 尝试通过REST创建文件夹时请求失败_Api_Office365 - Fatal编程技术网

Api 尝试通过REST创建文件夹时请求失败

Api 尝试通过REST创建文件夹时请求失败,api,office365,Api,Office365,我下载了一个示例,其中显示了我的OneDrive for Business中“与所有人共享”文件夹中的文件。很好! 但是,当我尝试创建一个文件夹或文件(没有内容)时,响应变成了一个坏请求 请求如下: string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/files", serviceInfo.ApiEndpoint); // Prepare the HTTP request:

我下载了一个示例,其中显示了我的OneDrive for Business中“与所有人共享”文件夹中的文件。很好! 但是,当我尝试创建一个文件夹或文件(没有内容)时,响应变成了一个坏请求

请求如下:

        string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/files", serviceInfo.ApiEndpoint);

        // Prepare the HTTP request:
        using (HttpClient client = new HttpClient())
        {
            Func<HttpRequestMessage> requestCreator = () =>
            {
                HttpRequestMessage request = new HttpRequestMessage( HttpMethod.Post, requestUrl);
                request.Headers.Add("Accept", "application/json;odata.metadata=full");                  
                request.Content = new StringContent(@"{'__metadata':{'type':'MS.FileServices.Folder'},Name:'TestFolder'}");
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                return request;
            };
string requestUrl=string.Format(CultureInfo.InvariantCulture,“{0}/files”,serviceInfo.apidendpoint);
//准备HTTP请求:
使用(HttpClient=new HttpClient())
{
Func requestCreator=()=>
{
HttpRequestMessage请求=新的HttpRequestMessage(HttpMethod.Post,requestUrl);
Add(“Accept”,“application/json;odata.metadata=full”);
request.Content=newstringcontent(@“{”uuuu元数据“:{”类型“:'MS.FileServices.Folder'},名称:'TestFolder'}”);
request.Content.Headers.ContentType=新的MediaTypeHeaderValue(“应用程序/json”);
返回请求;
};
}

而响应是一个错误的请求。 我认为我的问题在于“\uuu元数据”的json值。这是正确的吗?在哪里可以找到实现此操作的工作示例

提前谢谢

编辑:将API端点从“/\u API/web/getfolderbyserverrelativeurl('Documents')/files”更改为“\u API/files”。错误变为:“属性“\u metadata”在类型“MS.FileServices.FileSystemItem”上不存在。请确保仅使用由该类型定义的属性名称。”


我想我在这方面做得很好。但是,我仍然有一些问题。

我不确定这是否对您有帮助,因为这是属于oneDrive而不是oneDrive for business的。 此外,这些文件令人困惑:)

根据要求,要求应如下所示:

POST https://apis.live.net/v5.0/me/skydrive

Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{
    "name": "My example folder"
}
如果您可以看到头中有授权访问令牌


我看不到您向服务器发送了任何访问令牌。这就是为什么您的请求不正确。

我正在尝试下面的方法在SP中创建一个文件夹,它对我有效。希望它也能对你起作用

使用SharePoint Web API创建文件夹-

POST https://<Domain>.sharepoint.com/_api/web/folders
Accept: "application/json;odata=verbose"
Content-Type: "application/json"

{
  "ServerRelativeUrl": "/Shared Documents/<Folder-Name>"
}
POSThttps://.sharepoint.com/_api/web/folders
接受:“application/json;odata=verbose”
内容类型:“应用程序/json”
{
“ServerRelativeUrl”:“/共享文档/”
}