C#C
C#11mo ago
headrx

Ollama 404 http denial

Im attemping to write a Ollama front end and am having connection issues. Here is my http connection code.
csharp 
private async void Send_Message(string message)
{
    using (HttpClient client = new HttpClient())
    {
        var requestData = new
        {
            model = "llama3.2",
            prompt = message,
            stream = true
        };
        client.BaseAddress = new Uri("http://localhost:11434/api/generate");
        
        string jsonRequest = JsonSerializer.Serialize(requestData);
        var content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");

        // Send post request to the model
        HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);
        response.EnsureSuccessStatusCode();
        string jsonResponse = await response.Content.ReadAsStringAsync();

        ApiResponse apiResponse = JsonSerializer.Deserialize<ApiResponse>(jsonResponse);
        rtxtboxResponse.Document.Blocks.Add(new Paragraph(new Run(apiResponse.Response)));
    }

}

curl localhost:11434/api/generate -d "{\"model\":\"llama3.2:latest\",\"prompt\":\"hi\",\"stream\":false}"


I am able to curl , as well as just browse to the base url to show connectivity via browser , so i know its correctly running. If i curl to the BaseAddress with the request data included it correctly works, btu i cant get my code ot connect at all. It 404's me all day. Any ideas ?
image.png
image.png
Was this page helpful?