Skip to content

Commit 4b182e6

Browse files
committed
fix: http System.InvalidOperationException (#476)
1 parent 82ae44f commit 4b182e6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Models/OpenAI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Net.Http;
4+
using System.Text;
45
using System.Text.Json;
56
using System.Text.Json.Serialization;
67
using System.Threading;
@@ -105,11 +106,10 @@ public static OpenAIChatResponse Chat(string prompt, string question, Cancellati
105106
chat.AddMessage("user", question);
106107

107108
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) };
108-
client.DefaultRequestHeaders.Add("Content-Type", "application/json");
109109
if (!string.IsNullOrEmpty(ApiKey))
110110
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}");
111111

112-
var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest));
112+
var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest), Encoding.UTF8, "application/json");
113113
try
114114
{
115115
var task = client.PostAsync(Server, req, cancellation);

0 commit comments

Comments
 (0)