From 4b182e6ecdb34123ff2f473bb4d6ab81a5959aa8 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 16 Sep 2024 15:41:49 +0800 Subject: [PATCH] fix: http System.InvalidOperationException (#476) --- src/Models/OpenAI.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/OpenAI.cs b/src/Models/OpenAI.cs index 2619f299..5ab0c7ee 100644 --- a/src/Models/OpenAI.cs +++ b/src/Models/OpenAI.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net.Http; +using System.Text; using System.Text.Json; using System.Text.Json.Serialization; using System.Threading; @@ -105,11 +106,10 @@ namespace SourceGit.Models chat.AddMessage("user", question); var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) }; - client.DefaultRequestHeaders.Add("Content-Type", "application/json"); if (!string.IsNullOrEmpty(ApiKey)) client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}"); - var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest)); + var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest), Encoding.UTF8, "application/json"); try { var task = client.PostAsync(Server, req, cancellation);