xamarin.forms - 简单的 Odata 客户端使用身份验证不工作的 Odata
问题描述
我是 Simple.Odata.client 的新手。我在使用以下代码访问 Odata 服务时遇到问题。下面的代码返回 null。但邮递员返回结果。
- 疑似问题:如何传递带有 '1000' &format=json 的 url 字符串
- 下面的简单 odata 客户端设置是否正确?
Simple Odata客户端没有UrlBase,但是有BAseUri
这是 ODataClientSettings 工作吗?
var settings = new Simple.OData.Client.ODataClientSettings();
settings.BaseUri = new Uri(" https://..../UoM ?$filter=wer eg '1000' &format=json");
settings.Credentials = new NetworkCredential("user1", "usrpwd");
var client = new ODataClient(settings);
请帮忙
谢谢
解决方案
这对我有用
var credentials = new NetworkCredential(userName, password); //you can use the override with the domain too.
var settings = new ODataClientSettings(baseUrl, credentials) //baseUrl is a string.
{
IgnoreResourceNotFoundException = true,
OnTrace = (x, y) => Debug.WriteLine(x, y),
PayloadFormat = ODataPayloadFormat.Json, //here is where you specify the format
IgnoreUnmappedProperties = true,
RenewHttpConnection = true,
TraceFilter = ODataTrace.All,
PreferredUpdateMethod = ODataUpdateMethod.Merge
};
var client = new ODataClient(settings);
您的 baseUrl 不应包含所有这些 OData 标记,而是您的服务的端点,例如https://myservice.mysite.com/api.svc。然后,当您使用Simple.OData.Client时,资源 url 将自动完成。
请查看OData标准以了解其工作原理,并查看 Simple.OData.Client 存储库的示例以更好地了解如何使用它。
为了更好地了解如何使用 Windows 身份验证,您可以查看Authentication and Authorization with Windows Accounts以及如何使用 Windows 凭据访问网站
希望这有帮助。
推荐阅读
- arrays - 如何将空数组推入包含对象列表的非空数组?
- c# - 使用 Builder 模式和受保护的访问修饰符
- spring-boot - 从@configuration 获取空值
- python - 在 Python 中,为什么 .append 给出的结果与使用 + 不同?
- javascript - 如何暂停动画
- angular - 如何访问对象的数据?
- php - 迁移 Laravel 5.8 时出错外键
- c# - 在 join 语句中强制转换对象
- sql-server - apache nifi 可以检测数据库表记录更改以及如何检测?
- c# - maxDegreeOfParallelism 是否会阻止所有其他 Parallel.ForEach 创建新任务?