The request was aborted: Could not create SSL/TLS secure channel Ask Question
By   Junaid A     30-Dec-2024    1

I am calling chatGPT API and getting following error "The request was aborted: Could not create SSL/TLS secure channel."

Solutions


Junaid A

By adding this line my issues was fixed

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


I added above line of code in my , logic, where was calling api using httpclient example


var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.openai.com/v1/chat...");
request.Headers.Add("Authorization", "Bearer sk-***********************************************");
var content = new StringContent("{\r\n \"model\": \"gpt-3.5-turbo\",\r\n \"messages\": [\r\n {\r\n \"role\": \"system\",\r\n \"content\": \"You are a helpful assistant.\"\r\n },\r\n {\r\n \"role\": \"user\",\r\n \"content\": \""+kw+"\"\r\n }\r\n ]\r\n }", null, "application/json");

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
var r = await response.Content.ReadAsStringAsync();

// Console.WriteLine(response.Content);
var myDeserializedClass = JsonConvert.DeserializeObject<RootChat>(r);

10383
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM