且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

简单的 Odata 客户端 - 如何在每个请求标头中添加 oAuth 令牌?

更新时间:2023-09-08 10:43:52

显然我应该解释为什么这是答案.

Apparently I should provide an explanation of why this is the answer.

说明:这是为 Simple ODataClient 添加令牌的方式.

Explanation: this is how you add the token for Simple ODataClient.

var settings = new ODataClientSettings(new Uri("http://localhost:9000/"));
settings.BeforeRequest += delegate(HttpRequestMessage message)
{
    message.Headers.Add("Authorization", "Bearer " + token.AccessToken);
};

var client = new ODataClient(settings);