当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.SetBasicAuthentication方法代码示例

本文整理汇总了C#中HttpClient.SetBasicAuthentication方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.SetBasicAuthentication方法的具体用法?C# HttpClient.SetBasicAuthentication怎么用?C# HttpClient.SetBasicAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpClient的用法示例。


在下文中一共展示了HttpClient.SetBasicAuthentication方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var handler = new WebRequestHandler();
            handler.ClientCertificates.Add(
                X509.CurrentUser
                    .My
                    .SubjectDistinguishedName
                    .Find("CN=client")
                    .First());

            //var handler = new HttpClientHandler
            //{
            //    ClientCertificateOptions = ClientCertificateOption.Automatic
            //};

            var client = new HttpClient(handler)
            {
                BaseAddress = new Uri("https://web.local:444/api/")
            };

            client.SetBasicAuthentication("bob", "bob");

            var result = client.GetStringAsync("identity").Result;
            Console.WriteLine(JArray.Parse(result));
        }
开发者ID:Bihari,项目名称:Thinktecture.IdentityModel,代码行数:25,代码来源:Program.cs

示例2: GetToken

        private static string GetToken()
        {
            var client = new HttpClient();
            client.SetBasicAuthentication("dominick", "abc!123");

            // SAML11
            //var response = client.GetAsync("https://idsrv.local/issue/simple?realm=urn:testrp&tokenType=saml11").Result;
            
            // SAML2
            var response = client.GetAsync("https://idsrv.local/issue/simple?realm=urn:testrp&tokenType=saml2").Result;
            response.EnsureSuccessStatusCode();

            var tokenResponse = response.Content.ReadAsStringAsync().Result;
            var json = JObject.Parse(tokenResponse);
            return json["access_token"].ToString();
        }
开发者ID:RyanLiu99,项目名称:Thinktecture.IdentityModel,代码行数:16,代码来源:Program.cs

示例3: GetToken

        private static string GetToken()
        {
            "Requesting token".ConsoleYellow();

            var client = new HttpClient
            {
                BaseAddress = new Uri(simpleHttpEndpoint)
            };

            client.SetBasicAuthentication("bob", "abc!123");

            var response = client.GetAsync("?realm=http://sbserver/swttest/&tokentype=swt").Result;
            response.EnsureSuccessStatusCode();

            var tokenResponse = response.Content.ReadAsStringAsync().Result;
            var token = JObject.Parse(tokenResponse)["access_token"].ToString();

            Console.WriteLine(token);

            return token;
        }
开发者ID:EduOrtega,项目名称:Thinktecture.IdentityServer.v2,代码行数:21,代码来源:Program.cs

示例4: RevokeToken

        //static TokenResponse GetClientToken()
        //{
        //    var client = new OAuth2Client(
        //        new Uri("https://HFL0100:44333/connect/token"),
        //        "silicon",
        //        "F621F470-9731-4A25-80EF-67A6F7C5F4B8");
        //    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        //    return client.RequestClientCredentialsAsync("api1").Result;
        //}
        static TokenResponse RevokeToken(string token)
        {
            //var client = new OAuth2Client(
            //    new Uri("https://HFL0100:44333/connect/revocation"),
            //    "carbon",
            //    "21B5F798-BE55-42BC-8AA8-0025B903DC3B");
            //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            //var a = new System.Collections.Generic.Dictionary<string, string>();
            //a.Add("token", token);
            //a.Add("token_type_hint", "access_token");
            //return client.  (a).Result;

            var client = new HttpClient();
            client.SetBasicAuthentication("carbon", "21B5F798-BE55-42BC-8AA8-0025B903DC3B");
            var postBody = new System.Collections.Generic.Dictionary<string, string>
            {
            { "token", token },
            //{ "token_type_hint", "refresh_token" }
            { "token_type_hint", "access_token" }
            };
            var result = client.PostAsync("https://HFL0100:44333/connect/revocation", new FormUrlEncodedContent(postBody)).Result;

            return null;
        }
开发者ID:okusnadi,项目名称:IdentityServer3_WebApi_AngularJs_SSO_BearerToken,代码行数:33,代码来源:Program.cs


注:本文中的HttpClient.SetBasicAuthentication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。