C# json baglantısı hatası form application

cengizhanr

Centipat
Katılım
14 Eylül 2023
Mesajlar
17
Daha fazla  
Cinsiyet
Erkek
"if clicked buton1 say in the html code : SyntaxError: Unexpected token in JSON at position 71 at JSON.parse (<anonymous>) at parse (/home/runner/Cluster-2/node_modules/body-parser/lib/types/json.js:92:19) at /home/runner/Cluster-2/node_modules/body-parser/lib/read.js:128:18 at AsyncResource.runInAsyncScope (node:async_hooks:203:9) at invokeCallback (/home/runner/Cluster-2/node_modules/raw-body/index.js:238:16) at done (/home/runner/Cluster-2/node_modules/raw-body/index.js:227:7) at IncomingMessage.onEnd (/home/runner/Cluster-2/node_modules/raw-body/index.js:287:7) at IncomingMessage.emit (node:events:513:28) at IncomingMessage.emit (node:domain:489:12)" Hata bu kod
C#:
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http.Json;

namespace GenesisAPIFormApplication
{
    public partial class Form1 : Form
    {
        private string apiUrl = "https://cluster-2.pudochu.repl.co/api/genesis";
        private HttpClient httpClient = new HttpClient();

        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            // Sabit bir metin kullanarak API'ye metin gönderme işlemi
            string prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: İsmin ne?\nJarvis:";

            try
            {
                var response = await httpClient.PostAsJsonAsync(apiUrl, new { prompt = prompt, model = "text-dream-001" });

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();
                    MessageBox.Show(responseString);
                }
                else
                {
                    MessageBox.Show($"HTTP Hata Kodu: {response.StatusCode}");
                    // HTTP hata kodunu burada işleyebilirsiniz.
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("İstek gönderilirken bir hata meydana geldi: " + ex.Message);
            }
        }
    }
}
 

Technopat Haberler

Yeni konular

Geri
Yukarı