小编Sal*_*vat的帖子

当文件夹名称中使用百分号 (%) 时,Sharepoint REST API GetFolderByServerRelativePath 返回错误

我使用HTTP post方式上传文件,如下图:

POST https://sitename.sharepoint.com/sites/subsitename/pagename/_api/web/getfolderbyserverrelativepath(decodedurl=@t)/files/addusingpath(overwrite=true,decodedurl=@f)?@t='docs/%24%26%2B%2C%3B%3D%40%23%25%7B++++%7D%5E%7E%5B%5D%60'&@f='new.docx' HTTP/1.1

    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
Run Code Online (Sandbox Code Playgroud)

它适用于任何文件和文件夹,但文件夹名称中带有百分号(“%”)的文件夹除外。如果目标文件夹名称包含百分号(“%”),则会返回错误并显示消息:

{"error":{"code":"-2147024893, System.IO.DirectoryNotFoundException","message":{"lang":"en-US","value":"File Not Found."}}}
Run Code Online (Sandbox Code Playgroud)

我找到了相关文章:https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/supporting-and-in-file-and-folder-with-the-resourcepath-api

因此,我尝试使用另一种post方法:

POST https://sitename.sharepoint.com/sites/subsitename/pagename/_api/web/getfolderbyserverrelativepath(decodedurl=@t)/files/addstubusingpath(decodedurl=@f)?@t='docs/%24%26%2B%2C%3B%3D%40%23%25%7B++++%7D%5E%7E%5B%5D%60'&@f='new.docx' HTTP/1.1

    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
Run Code Online (Sandbox Code Playgroud)

但我得到了如下回复:

{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Not well formatted JSON stream."}}}
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?

api rest sharepoint

0
推荐指数
1
解决办法
9232
查看次数

标签 统计

api ×1

rest ×1

sharepoint ×1