Skip to content

HttpClient BaseAddress #3

@marcelagraz

Description

@marcelagraz

I was having this error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
System.InvalidOperationException: An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
   at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
   at System.Net.Http.HttpClient.CheckRequestBeforeSend(HttpRequestMessage request)
   at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at SmartGraphQLClient.Core.GraphQLRequestExecutor.GraphQLRequestExecutor.ExecuteQueryAsync(String queryString, CancellationToken token)
   at SmartGraphQLClient.Core.GraphQLRequestExecutor.GraphQLRequestExecutor.ExecuteAsync(String queryString, CancellationToken token)
   at SmartGraphQLClient.Core.GraphQLRequestExecutor.GraphQLRequestExecutor.<ExecuteToArrayAsync>d__11`1[[BlazorGraphQLApp.Shared.Database.Product, BlazorGraphQLApp.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at SmartGraphQLClient.Core.GraphQLQueryable.GraphQLQueryable`1.<ToListAsync>d__42[[BlazorGraphQLApp.Shared.Database.Product, BlazorGraphQLApp.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at BlazorGraphQLApp.Client.Pages.FetchData.OnInitializedAsync() in C:\Users\User01\source\repos\BlazorGraphQLApp\BlazorGraphQLApp\Client\Pages\FetchData.razor:line 50
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

I had to add:

services.AddHttpClient<GraphQLHttpClient>("GraphQLHttpClient", client => 
{ 
    if (client is not null) 
        client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress + "graphql"); 
});

services.AddSmartGraphQLClient();

to get the client working in a Blazor wasm app.

Is there any other way of setting up the HttpClient BaseAddress?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions