From 434c84ce5c07b684c0bb3e7e95c5ebad1c2365a9 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Mon, 24 Jun 2024 11:41:03 +1000 Subject: [PATCH] Add user agent so non-api requests work again --- RestService.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RestService.cs b/RestService.cs index 90f63ae..c83b9ea 100644 --- a/RestService.cs +++ b/RestService.cs @@ -3,7 +3,9 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; using Neighbourhood.omg.lol.Models; using System.Diagnostics; +using System.Net; using System.Net.Http.Json; +using System.Reflection; using System.Text; using System.Text.Json; using System.Text.RegularExpressions; @@ -17,6 +19,8 @@ namespace Neighbourhood.omg.lol { public RestService(string? token = null) { _client = new HttpClient(); _client.BaseAddress = new Uri(BaseUrl); + AssemblyName name = Assembly.GetExecutingAssembly().GetName(); + _client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(name.Name ?? "Neighbourhood.omg.lol", name.Version?.ToString())); _serializerOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, WriteIndented = true