コード例 #1
0
ファイル: ClientDemoService.cs プロジェクト: wulienen/abp
        /// <summary>
        /// Shows how to manually create an HttpClient and authenticate using the
        /// IIdentityModelHttpClientAuthenticator service.
        /// </summary>
        private async Task TestWithHttpClient()
        {
            Console.WriteLine();
            Console.WriteLine("*** TestWithHttpClient ************************************");

            try
            {
                using (var client = new HttpClient())
                {
                    await _authenticator.AuthenticateAsync(client);

                    var response = await client.GetAsync(_remoteServiceOptions.RemoteServices.Default.BaseUrl.EnsureEndsWith('/') + "Test/Index");

                    if (!response.IsSuccessStatusCode)
                    {
                        Console.WriteLine(response.StatusCode);
                    }
                    else
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        Console.WriteLine(content);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #2
0
        /// <summary>
        /// Shows how to manually create an HttpClient and authenticate using the
        /// IIdentityModelHttpClientAuthenticator service.
        /// </summary>
        private async Task TestWithHttpClient()
        {
            Console.WriteLine();
            Console.WriteLine("*** TestWithHttpClient ************************************");

            try
            {
                using (var client = new HttpClient())
                {
                    await _authenticator.AuthenticateAsync(client);

                    var url = GetServerUrl() + "Test/Index";

                    var response = await client.GetAsync(url);

                    if (!response.IsSuccessStatusCode)
                    {
                        Console.WriteLine(response.StatusCode);
                    }
                    else
                    {
                        var responseContent = await response.Content.ReadAsStringAsync();

                        Console.WriteLine(responseContent);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        /// <param name="authenticator">Authenticator object</param>
        /// <param name="client"><see cref="HttpClient"/> object to be authenticated</param>
        /// <param name="identityClientName">The identity client name configured with the <see cref="IdentityClientOptions"/>.</param>
        public static Task AuthenticateAsync(
            [NotNull] this IIdentityModelHttpClientAuthenticator authenticator,
            [NotNull] HttpClient client, 
            string identityClientName = null)
        {
            Check.NotNull(authenticator, nameof(authenticator));

            return authenticator.AuthenticateAsync(
                new IdentityModelHttpClientAuthenticateContext(
                    client,
                    identityClientName
                )
            );
        }
コード例 #4
0
        /// <summary>
        /// Shows how to manually create an HttpClient and authenticate using the
        /// IIdentityModelHttpClientAuthenticator service.
        /// </summary>
        private async Task TestWithHttpClient()
        {
            Console.WriteLine("*** TestWithHttpClient ***");

            using (var client = new HttpClient())
            {
                await _authenticator.AuthenticateAsync(client);

                var response = await client.GetAsync("http://localhost:63568/Test");

                if (!response.IsSuccessStatusCode)
                {
                    Console.WriteLine(response.StatusCode);
                }
                else
                {
                    var content = await response.Content.ReadAsStringAsync();

                    Console.WriteLine(content);
                }
            }
        }