SharePoint REST-为什么更新元数据返回204而不是200?

用户1398291

使用以下端点,我们可以更新特定文件的元数据:https : //domain.example.com/_api/web/GetFileByServerRelativeUrl(URL)/ListItemAllFields

成功更新元数据后,为什么API返回204而不是200。这是预期的还是存在其他更新元数据的方式。

蒂姆·哈奇森

根据Dynamics Web API文档,默认值为更新数据而不返回更新的结果。这就是为什么您获得状态代码204的原因。为了获取返回的数据,您将需要prefer:return=representation在Web API调用中添加标头。添加prefer标头将返回状态码200。

C#示例

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Helpers.GetSystemUrl(APIConnector.Application.Dynamics));
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
client.DefaultRequestHeaders.Add("prefer", "return=representation");

打字稿示例

let xhr = new XMLHttpRequest();
xhr.open("PATCH", CONNECTION_URL, true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("OData-MaxVersion", "4.0");
xhr.setRequestHeader("OData-Version", "4.0");
xhr.setRequestHeader("Content-Type", "application/json");          
xhr.setRequestHeader("prefer", "return=representation");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Sharepoint Foundation REST 接口,更新对象失败

使用REST API更新Sharepoint元数据会产生400错误的请求错误

microsoft sharepoint 使用 REST API 访问文档返回 404

Sharepoint 2013 REST API不会返回列表的所有项目

SharePoint Rest 调用未返回所有字段

Sharepoint Rest 不返回标题以数字开头的字段

使用Rest API更新Sharepoint中的多项选择字段

我需要什么权限才能使用 SharePoint 的 REST API 获取 SharePoint 网站的请求摘要?

什么是用于删除 SharePoint 文档特定版本的 REST API 端点

使用从SharePoint文档库中获取的REST API筛选数据

使用REST API获取SharePoint People Picker数据

使用REST API获取SharePoint列表的不同数据

如何进行rest调用返回所有结果或总数(Sharepoint REST API)

使用rest api的sharepoint搜索

使用Rest更新SharePoint列表中的文本字段将返回错误代码400

使用 Sharepoint REST API 和 Javascript 从 Sharepoint 外部上传文件?

Sharepoint REST api - 领域不是当前服务命名空间的配置领域错误 50169

使用 api Sharepoint 和 Postman 更新 Sharepoint 元数据列

Sharepoint 2013 REST API GetFolderByServerRelativeUrl将不会返回作者详细信息

通过Sharepoint REST发送列表更新时,如何处理“操作中止”错误?

无法在 Sharepoint 2016 中使用 REST API 更新列表中的列表项

使用 Rest API 调用执行批量更新/插入 SharePoint 列表项的 C# 代码

jQuery自动完成使用使用Ajax REST从SharePoint列表中提取的数据

使用REST的SharePoint2013内部部署检索用户配置文件数据插件

SharePoint REST:字段或属性不存在

SharePoint REST查询展开“自引用”列

Sharepoint 授权令牌在 REST api 中的使用

Sharepoint REST API和MVC AAD连接

通过REST API for Sharepoint吸引MSOL用户