コード例 #1
0
        public async Task <string> SendAsync(string url)
        {
            var client         = HttpClientFactory.CreateClient();
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);

            var uri = new Uri(url, UriKind.RelativeOrAbsolute);

            if (!uri.IsAbsoluteUri)
            {
                var baseUrl = string.Empty;
                try
                {
                    //Blazor tiered -- mode
                    var remoteServiceConfig = RemoteServiceOptions.RemoteServices.GetConfigurationOrDefault("Default");
                    baseUrl            = remoteServiceConfig.BaseUrl;
                    client.BaseAddress = new Uri(baseUrl);
                    AddHeaders(requestMessage);
                    await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client,
                                                                                                              requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty));
                }
                catch (AbpException) // Blazor-Server mode.
                {
                    baseUrl            = NavigationManager.BaseUri;
                    client.BaseAddress = new Uri(baseUrl);
                    foreach (var header in HttpContextAccessor.HttpContext.Request.Headers)
                    {
                        requestMessage.Headers.Add(header.Key, header.Value.ToArray());
                    }
                }
            }

            var response = await client.SendAsync(requestMessage);

            return(await response.Content.ReadAsStringAsync());
        }
コード例 #2
0
        public async Task <string> SendAsync(string url)
        {
            var client         = HttpClientFactory.CreateClient();
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);

            AddHeaders(requestMessage);

            var uri = new Uri(url, UriKind.RelativeOrAbsolute);

            if (!uri.IsAbsoluteUri)
            {
                var remoteServiceConfig = RemoteServiceOptions.RemoteServices.GetConfigurationOrDefault("Default");
                client.BaseAddress = new Uri(remoteServiceConfig.BaseUrl);
                await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(remoteServiceConfig.BaseUrl), string.Empty));
            }

            var response = await client.SendAsync(requestMessage);

            return(await response.Content.ReadAsStringAsync());
        }