From cb6858fe31b9784e02ccee1d92e9e27d115d8d06 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 26 Mar 2020 10:13:23 -0700 Subject: [PATCH] Update to using System.Net.Http.Json (#20195) --- eng/Dependencies.props | 1 + eng/ProjectReferences.props | 1 - eng/Version.Details.xml | 4 + eng/Versions.props | 1 + .../test/RuntimeDependenciesResolverTest.cs | 3 +- .../Http/src/HttpClientJsonExtensions.cs | 121 ---------- ...rosoft.AspNetCore.Blazor.HttpClient.csproj | 18 -- .../Http/test/HttpClientJsonExtensionsTest.cs | 209 ------------------ ....AspNetCore.Blazor.HttpClient.Tests.csproj | 11 - .../StandaloneApp/Pages/FetchData.razor | 2 +- .../StandaloneApp/StandaloneApp.csproj | 2 +- .../testassets/StandaloneApp/_Imports.razor | 1 + .../Pages/FetchData.razor | 2 +- .../Wasm.Authentication.Client.csproj | 2 +- .../Wasm.Authentication.Client/_Imports.razor | 1 + .../ServerAuthenticationStateProvider.cs | 3 +- .../BasicTestApp/BasicTestApp.csproj | 2 +- ...ponentsWebAssembly-CSharp.Client.csproj.in | 2 +- ...re.Components.WebAssembly.Templates.csproj | 2 +- .../Client/Pages/FetchData.razor | 6 +- .../Client/_Imports.razor | 1 + 21 files changed, 22 insertions(+), 373 deletions(-) delete mode 100644 src/Components/WebAssembly/Http/src/HttpClientJsonExtensions.cs delete mode 100644 src/Components/WebAssembly/Http/src/Microsoft.AspNetCore.Blazor.HttpClient.csproj delete mode 100644 src/Components/WebAssembly/Http/test/HttpClientJsonExtensionsTest.cs delete mode 100644 src/Components/WebAssembly/Http/test/Microsoft.AspNetCore.Blazor.HttpClient.Tests.csproj diff --git a/eng/Dependencies.props b/eng/Dependencies.props index 1a5b5d456c..d7f37d2f34 100644 --- a/eng/Dependencies.props +++ b/eng/Dependencies.props @@ -90,6 +90,7 @@ and are generated based on the last package release. + diff --git a/eng/ProjectReferences.props b/eng/ProjectReferences.props index 6fa112f0b3..c98b182a03 100644 --- a/eng/ProjectReferences.props +++ b/eng/ProjectReferences.props @@ -7,7 +7,6 @@ - diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 2fe71a0b04..f8f61f056f 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -13,6 +13,10 @@ https://github.com/dotnet/blazor 42941006ace24b5cb66a99ff52828a935f62ebcf + + https://github.com/dotnet/corefx + 6ab82925fc3ca30b3c7e6ba060d0d5bd5ae76b06 + diff --git a/eng/Versions.props b/eng/Versions.props index cb0dc7525c..036576257b 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -93,6 +93,7 @@ 4.7.0 4.7.0 4.7.1 + 3.2.0-preview3.20175.8 4.7.0 4.7.0 diff --git a/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs b/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs index e1dc083728..19efce0504 100644 --- a/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs +++ b/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs @@ -41,8 +41,6 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build fewer assemblies from the server, and during publishing, illink would remove all the uncalled implementation code from mscorlib.dll anyway. */ - "Microsoft.AspNetCore.Blazor.HttpClient.dll", - "Microsoft.AspNetCore.Blazor.HttpClient.pdb", "Microsoft.AspNetCore.Components.dll", "Microsoft.AspNetCore.Components.Forms.dll", "Microsoft.AspNetCore.Components.Web.dll", @@ -81,6 +79,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build "System.IO.Compression.FileSystem.dll", "System.Memory.dll", "System.Net.Http.dll", + "System.Net.Http.Json.dll", "System.Numerics.dll", "System.Numerics.Vectors.dll", "System.Runtime.CompilerServices.Unsafe.dll", diff --git a/src/Components/WebAssembly/Http/src/HttpClientJsonExtensions.cs b/src/Components/WebAssembly/Http/src/HttpClientJsonExtensions.cs deleted file mode 100644 index db691257aa..0000000000 --- a/src/Components/WebAssembly/Http/src/HttpClientJsonExtensions.cs +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Net.Http; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Components -{ - /// - /// Extension methods for working with JSON APIs. - /// - public static class HttpClientJsonExtensions - { - /// - /// Sends a GET request to the specified URI, and parses the JSON response body - /// to create an object of the generic type. - /// - /// A type into which the response body can be JSON-deserialized. - /// The . - /// The URI that the request will be sent to. - /// The response parsed as an object of the generic type. - public static async Task GetJsonAsync(this HttpClient httpClient, string requestUri) - { - var stringContent = await httpClient.GetStringAsync(requestUri); - return JsonSerializer.Deserialize(stringContent, JsonSerializerOptionsProvider.Options); - } - - /// - /// Sends a POST request to the specified URI, including the specified - /// in JSON-encoded format, and parses the JSON response body to create an object of the generic type. - /// - /// The . - /// The URI that the request will be sent to. - /// Content for the request body. This will be JSON-encoded and sent as a string. - /// The response parsed as an object of the generic type. - public static Task PostJsonAsync(this HttpClient httpClient, string requestUri, object content) - => httpClient.SendJsonAsync(HttpMethod.Post, requestUri, content); - - /// - /// Sends a POST request to the specified URI, including the specified - /// in JSON-encoded format, and parses the JSON response body to create an object of the generic type. - /// - /// A type into which the response body can be JSON-deserialized. - /// The . - /// The URI that the request will be sent to. - /// Content for the request body. This will be JSON-encoded and sent as a string. - /// The response parsed as an object of the generic type. - public static Task PostJsonAsync(this HttpClient httpClient, string requestUri, object content) - => httpClient.SendJsonAsync(HttpMethod.Post, requestUri, content); - - /// - /// Sends a PUT request to the specified URI, including the specified - /// in JSON-encoded format. - /// - /// The . - /// The URI that the request will be sent to. - /// Content for the request body. This will be JSON-encoded and sent as a string. - public static Task PutJsonAsync(this HttpClient httpClient, string requestUri, object content) - => httpClient.SendJsonAsync(HttpMethod.Put, requestUri, content); - - /// - /// Sends a PUT request to the specified URI, including the specified - /// in JSON-encoded format, and parses the JSON response body to create an object of the generic type. - /// - /// A type into which the response body can be JSON-deserialized. - /// The . - /// The URI that the request will be sent to. - /// Content for the request body. This will be JSON-encoded and sent as a string. - /// The response parsed as an object of the generic type. - public static Task PutJsonAsync(this HttpClient httpClient, string requestUri, object content) - => httpClient.SendJsonAsync(HttpMethod.Put, requestUri, content); - - /// - /// Sends an HTTP request to the specified URI, including the specified - /// in JSON-encoded format. - /// - /// The . - /// The HTTP method. - /// The URI that the request will be sent to. - /// Content for the request body. This will be JSON-encoded and sent as a string. - public static Task SendJsonAsync(this HttpClient httpClient, HttpMethod method, string requestUri, object content) - => httpClient.SendJsonAsync(method, requestUri, content); - - /// - /// Sends an HTTP request to the specified URI, including the specified - /// in JSON-encoded format, and parses the JSON response body to create an object of the generic type. - /// - /// A type into which the response body can be JSON-deserialized. - /// The . - /// The HTTP method. - /// The URI that the request will be sent to. - /// Content for the request body. This will be JSON-encoded and sent as a string. - /// The response parsed as an object of the generic type. - public static async Task SendJsonAsync(this HttpClient httpClient, HttpMethod method, string requestUri, object content) - { - var requestJson = JsonSerializer.Serialize(content, JsonSerializerOptionsProvider.Options); - var response = await httpClient.SendAsync(new HttpRequestMessage(method, requestUri) - { - Content = new StringContent(requestJson, Encoding.UTF8, "application/json") - }); - - // Make sure the call was successful before we - // attempt to process the response content - response.EnsureSuccessStatusCode(); - - if (typeof(T) == typeof(IgnoreResponse)) - { - return default; - } - else - { - var stringContent = await response.Content.ReadAsStringAsync(); - return JsonSerializer.Deserialize(stringContent, JsonSerializerOptionsProvider.Options); - } - } - - class IgnoreResponse { } - } -} diff --git a/src/Components/WebAssembly/Http/src/Microsoft.AspNetCore.Blazor.HttpClient.csproj b/src/Components/WebAssembly/Http/src/Microsoft.AspNetCore.Blazor.HttpClient.csproj deleted file mode 100644 index ae4ee9a8a8..0000000000 --- a/src/Components/WebAssembly/Http/src/Microsoft.AspNetCore.Blazor.HttpClient.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - netstandard2.0 - Provides experimental support for using System.Text.Json with HttpClient. Intended for use with Blazor running under WebAssembly. - true - false - - - - - - - - - - - diff --git a/src/Components/WebAssembly/Http/test/HttpClientJsonExtensionsTest.cs b/src/Components/WebAssembly/Http/test/HttpClientJsonExtensionsTest.cs deleted file mode 100644 index f8d31fd073..0000000000 --- a/src/Components/WebAssembly/Http/test/HttpClientJsonExtensionsTest.cs +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net; -using System.Net.Http; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Xunit; - -namespace Microsoft.AspNetCore.Components.Test -{ - public class HttpClientJsonExtensionsTest - { - private readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - PropertyNameCaseInsensitive = true, - }; - - const string TestUri = "http://example.com/some/uri"; - - [Fact] - public async Task GetJson_Success() - { - // Arrange - var httpClient = new HttpClient(new TestHttpMessageHandler(req => - { - Assert.Equal(TestUri, req.RequestUri.AbsoluteUri); - return Task.FromResult(CreateJsonResponse(HttpStatusCode.OK, new Person - { - Name = "Abc", - Age = 123 - })); - })); - - // Act - var result = await httpClient.GetJsonAsync(TestUri); - - // Assert - Assert.Equal("Abc", result.Name); - Assert.Equal(123, result.Age); - } - - [Fact] - public async Task GetJson_Failure() - { - // Arrange - var httpClient = new HttpClient(new TestHttpMessageHandler(req => - { - Assert.Equal(TestUri, req.RequestUri.AbsoluteUri); - return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)); - })); - - // Act/Assert - var ex = await Assert.ThrowsAsync( - () => httpClient.GetJsonAsync(TestUri)); - Assert.Contains("404 (Not Found)", ex.Message); - } - - [Theory] - [InlineData("Put")] - [InlineData("Post")] - [InlineData("Patch")] - [InlineData("Delete")] - [InlineData("MyArtificialMethod")] - public async Task SendJson_Success(string httpMethodString) - { - var httpMethod = new HttpMethod(httpMethodString); - var requestContent = new { MyProp = true, OtherProp = "Hello" }; - - // Arrange - var httpClient = new HttpClient(new TestHttpMessageHandler(async req => - { - Assert.Equal(httpMethod, req.Method); - Assert.Equal(TestUri, req.RequestUri.AbsoluteUri); - Assert.Equal(JsonSerializer.Serialize(requestContent, _jsonSerializerOptions), await ((StringContent)req.Content).ReadAsStringAsync()); - return CreateJsonResponse(HttpStatusCode.OK, new Person - { - Name = "Abc", - Age = 123 - }); - })); - - // Act - var result = await Send(httpClient, httpMethodString, requestContent); - - // Assert - Assert.Equal("Abc", result.Name); - Assert.Equal(123, result.Age); - } - - [Fact] - public async Task ReadAsJsonAsync_ReadsCamelCasedJson() - { - var input = "{\"name\": \"TestPerson\", \"age\": 23 }"; - - // Arrange - var httpClient = new HttpClient(new TestHttpMessageHandler(req => - { - return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(input) - }); - })); - - // Act - var result = await httpClient.GetJsonAsync(TestUri); - - // Assert - Assert.Equal("TestPerson", result.Name); - Assert.Equal(23, result.Age); - } - - [Fact] - public async Task ReadAsJsonAsync_ReadsPascalCasedJson() - { - var input = "{\"Name\": \"TestPerson\", \"Age\": 23 }"; - - // Arrange - var httpClient = new HttpClient(new TestHttpMessageHandler(req => - { - return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(input) - }); - })); - - // Act - var result = await httpClient.GetJsonAsync(TestUri); - - // Assert - Assert.Equal("TestPerson", result.Name); - Assert.Equal(23, result.Age); - } - - [Theory] - [InlineData("Put")] - [InlineData("Post")] - [InlineData("Patch")] - [InlineData("Delete")] - [InlineData("MyArtificialMethod")] - public async Task SendJson_Failure(string httpMethodString) - { - var httpMethod = new HttpMethod(httpMethodString); - var requestContent = new { MyProp = true, OtherProp = "Hello" }; - - // Arrange - var httpClient = new HttpClient(new TestHttpMessageHandler(async req => - { - Assert.Equal(httpMethod, req.Method); - Assert.Equal(TestUri, req.RequestUri.AbsoluteUri); - Assert.Equal(JsonSerializer.Serialize(requestContent, _jsonSerializerOptions), await ((StringContent)req.Content).ReadAsStringAsync()); - return new HttpResponseMessage(HttpStatusCode.BadGateway); - })); - - // Act/Assert - var ex = await Assert.ThrowsAsync( - () => Send(httpClient, httpMethodString, requestContent)); - Assert.Contains("502 (Bad Gateway)", ex.Message); - } - - HttpResponseMessage CreateJsonResponse(HttpStatusCode statusCode, object content) - { - return new HttpResponseMessage(statusCode) - { - Content = new StringContent(JsonSerializer.Serialize(content, _jsonSerializerOptions)) - }; - } - - Task Send(HttpClient httpClient, string httpMethodString, object requestContent) - { - // For methods with convenience overloads, show those overloads work - switch (httpMethodString) - { - case "post": - return httpClient.PostJsonAsync(TestUri, requestContent); - case "put": - return httpClient.PutJsonAsync(TestUri, requestContent); - default: - return httpClient.SendJsonAsync(new HttpMethod(httpMethodString), TestUri, requestContent); - } - } - - class Person - { - public string Name { get; set; } - public int Age { get; set; } - } - - class TestHttpMessageHandler : HttpMessageHandler - { - private readonly Func> _sendDelegate; - - public TestHttpMessageHandler(Func> sendDelegate) - { - _sendDelegate = sendDelegate; - } - - protected override void Dispose(bool disposing) - => base.Dispose(disposing); - - protected override Task SendAsync( - HttpRequestMessage request, CancellationToken cancellationToken) - => _sendDelegate(request); - } - } -} diff --git a/src/Components/WebAssembly/Http/test/Microsoft.AspNetCore.Blazor.HttpClient.Tests.csproj b/src/Components/WebAssembly/Http/test/Microsoft.AspNetCore.Blazor.HttpClient.Tests.csproj deleted file mode 100644 index e7a9870ecd..0000000000 --- a/src/Components/WebAssembly/Http/test/Microsoft.AspNetCore.Blazor.HttpClient.Tests.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - $(DefaultNetCoreTargetFramework) - - - - - - - diff --git a/src/Components/WebAssembly/testassets/StandaloneApp/Pages/FetchData.razor b/src/Components/WebAssembly/testassets/StandaloneApp/Pages/FetchData.razor index c640fe9fbc..0ed7245e45 100644 --- a/src/Components/WebAssembly/testassets/StandaloneApp/Pages/FetchData.razor +++ b/src/Components/WebAssembly/testassets/StandaloneApp/Pages/FetchData.razor @@ -52,7 +52,7 @@ else protected override async Task OnParametersSetAsync() { startDate = StartDate.GetValueOrDefault(DateTime.Now); - forecasts = await Http.GetJsonAsync( + forecasts = await Http.GetFromJsonAsync( $"sample-data/weather.json?date={startDate.ToString("yyyy-MM-dd")}"); // Because StandaloneApp doesn't really have a server endpoint to get dynamic data from, diff --git a/src/Components/WebAssembly/testassets/StandaloneApp/StandaloneApp.csproj b/src/Components/WebAssembly/testassets/StandaloneApp/StandaloneApp.csproj index 555b2a1f7d..812f59e8c4 100644 --- a/src/Components/WebAssembly/testassets/StandaloneApp/StandaloneApp.csproj +++ b/src/Components/WebAssembly/testassets/StandaloneApp/StandaloneApp.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/Components/WebAssembly/testassets/StandaloneApp/_Imports.razor b/src/Components/WebAssembly/testassets/StandaloneApp/_Imports.razor index efbdfe11c5..99ac4c2596 100644 --- a/src/Components/WebAssembly/testassets/StandaloneApp/_Imports.razor +++ b/src/Components/WebAssembly/testassets/StandaloneApp/_Imports.razor @@ -1,4 +1,5 @@ @using System.Net.Http +@using System.Net.Http.Json @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web @using StandaloneApp diff --git a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Pages/FetchData.razor b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Pages/FetchData.razor index a4bd93d100..8b9fee7815 100644 --- a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Pages/FetchData.razor +++ b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Pages/FetchData.razor @@ -50,7 +50,7 @@ else if (tokenResult.TryGetToken(out var token)) { httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.Value}"); - forecasts = await httpClient.GetJsonAsync("WeatherForecast"); + forecasts = await httpClient.GetFromJsonAsync("WeatherForecast"); } else { diff --git a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Wasm.Authentication.Client.csproj b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Wasm.Authentication.Client.csproj index 814a5b3669..1c8f7b7100 100644 --- a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Wasm.Authentication.Client.csproj +++ b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Wasm.Authentication.Client.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/_Imports.razor b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/_Imports.razor index b1008d2585..8e3d12c353 100644 --- a/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/_Imports.razor +++ b/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/_Imports.razor @@ -1,4 +1,5 @@ @using System.Net.Http +@using System.Net.Http.Json @using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.WebAssembly.Authentication @using Microsoft.AspNetCore.Components.Forms diff --git a/src/Components/test/testassets/BasicTestApp/AuthTest/ServerAuthenticationStateProvider.cs b/src/Components/test/testassets/BasicTestApp/AuthTest/ServerAuthenticationStateProvider.cs index 31316f85c1..4f61a171b3 100644 --- a/src/Components/test/testassets/BasicTestApp/AuthTest/ServerAuthenticationStateProvider.cs +++ b/src/Components/test/testassets/BasicTestApp/AuthTest/ServerAuthenticationStateProvider.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Net.Http; +using System.Net.Http.Json; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; @@ -25,7 +26,7 @@ namespace BasicTestApp.AuthTest public override async Task GetAuthenticationStateAsync() { var uri = new Uri(_httpClient.BaseAddress, "/subdir/api/User"); - var data = await _httpClient.GetJsonAsync(uri.AbsoluteUri); + var data = await _httpClient.GetFromJsonAsync(uri.AbsoluteUri); ClaimsIdentity identity; if (data.IsAuthenticated) { diff --git a/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj b/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj index a4603fd72e..f6c755d21c 100644 --- a/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj +++ b/src/Components/test/testassets/BasicTestApp/BasicTestApp.csproj @@ -14,8 +14,8 @@ + - diff --git a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/ComponentsWebAssembly-CSharp.Client.csproj.in b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/ComponentsWebAssembly-CSharp.Client.csproj.in index f4f890bfea..e612662f2d 100644 --- a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/ComponentsWebAssembly-CSharp.Client.csproj.in +++ b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/ComponentsWebAssembly-CSharp.Client.csproj.in @@ -12,9 +12,9 @@ - + diff --git a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/Microsoft.AspNetCore.Components.WebAssembly.Templates.csproj b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/Microsoft.AspNetCore.Components.WebAssembly.Templates.csproj index 3774f45287..0619988876 100644 --- a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/Microsoft.AspNetCore.Components.WebAssembly.Templates.csproj +++ b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/Microsoft.AspNetCore.Components.WebAssembly.Templates.csproj @@ -29,6 +29,7 @@ MicrosoftEntityFrameworkCoreSqlServerPackageVersion=$(MicrosoftEntityFrameworkCoreSqlServerPackageVersion); MicrosoftEntityFrameworkCoreSqlitePackageVersion=$(MicrosoftEntityFrameworkCoreSqlitePackageVersion); MicrosoftEntityFrameworkCoreToolsPackageVersion=$(MicrosoftEntityFrameworkCoreToolsPackageVersion); + SystemNetHttpJsonPackageVersion=$(SystemNetHttpJsonPackageVersion) @@ -37,7 +38,6 @@ - diff --git a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/Pages/FetchData.razor b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/Pages/FetchData.razor index 84b610e5cd..a226098ce8 100644 --- a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/Pages/FetchData.razor +++ b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/Pages/FetchData.razor @@ -63,7 +63,7 @@ else if (tokenResult.TryGetToken(out var token)) { httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.Value}"); - forecasts = await httpClient.GetJsonAsync("WeatherForecast"); + forecasts = await httpClient.GetFromJsonAsync("WeatherForecast"); } else { @@ -71,10 +71,10 @@ else } #else - forecasts = await Http.GetJsonAsync("WeatherForecast"); + forecasts = await Http.GetFromJsonAsync("WeatherForecast"); #endif*@ #else - forecasts = await Http.GetJsonAsync("sample-data/weather.json"); + forecasts = await Http.GetFromJsonAsync("sample-data/weather.json"); #endif*@ } diff --git a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/_Imports.razor b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/_Imports.razor index 0029925574..d0897fa397 100644 --- a/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/_Imports.razor +++ b/src/ProjectTemplates/ComponentsWebAssembly.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/_Imports.razor @@ -1,4 +1,5 @@ @using System.Net.Http +@using System.Net.Http.Json @*#if (!NoAuth) @using Microsoft.AspNetCore.Components.Authorization #endif*@