Exception on the Httpresquest

Asked

Viewed 20 times

-1

I am developing a login system for my app made in windows Forms. I created an API that works normally by Swagger, but when I try to request a request from my system for the API an error occurs. I reviewed the system code and saw that the error is not in it, as I can use other Apis (e.g., Viacep).

private static string urlApi = "http://localhost:5001           /WeatherForecast/teste?strTeste=teste";  

        HttpRequestMessage request = new HttpRequestMessage();
        

        private static async Task<string> TesteDeApi()
        {
            int teste = 0;

            try
            {

                HttpClient httpClient = new HttpClient();
                HttpResponseMessage res = await httpClient.GetAsync(urlApi);
                HttpContent content = res.Content;
                string data = await content.ReadAsStringAsync();

                MessageBox.Show(data);
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            return teste.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TesteDeApi();
        }

Imagem do erro gerado ao executar a requisição

To make the request I use Httpclient. You could tell me why I made that mistake or how to fix it?

  • The url is with that space?

  • No, that space is because of the same stack. I managed to solve this error, however, now there is another error. He says that it is not possible to connect the API because the server actively refused.

  • But hence it is pq the API server not and running at the same time as your application

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.