如何使用ASP.NET Core Web应用程序查询OData服务

时间:2019-05-23 21:50:09

标签: asp.net-core odata

我正在尝试查询使用Odata公开数据的Microsoft Dynamics 365服务器。

要查询的Ajax请求就是这样

var entity = {};
entity.dfnd_financingused = 1;

var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/location(loc='LOC-EXAMPLE')", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("If-Match", "*");
req.onreadystatechange = function() {
   if (this.readyState === 4) {
       req.onreadystatechange = null;
       if (this.status === 204) {
           //Success - No Return Data - Do Something
       } else {
           Xrm.Utility.alertDialog(this.statusText);
       }
   }
};
req.send(JSON.stringify(entity));

我需要通过.NetCore API HttpClient来使用它吗? OData版本信息会这样吗?

 client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");

有正确/更好的方法吗?

预先感谢

0 个答案:

没有答案