Hello everybody, i have the c# code below to connect with Gemini AI and make requests with API (window application), the problem is the application is running perfect but only for me (windows 11), the other users get error 400 bad request. please could you help me to solve the problem? here is my code:
C#:
string apiKey = "XXXXXXXXXXXXXXXXXXXXX";
string prompt = "Search for: " + richTextBox1.Text;
string jsonData = "{\"contents\":[{\"parts\":[{\"text\":\"" + prompt.Replace("\"", "\\\"") + "\"}]}]}";
string url = "URL TO gemini-1.5-pro:generateContent?key=" + apiKey;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(jsonData);
streamWriter.Flush();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string result = reader.ReadToEnd();
richTextBox2.Text = result;
}
Last edited by a moderator: