Problem raising API and making request via Postman

Asked

Viewed 166 times

-1

I’m creating an API project in dotnet core and I’m not being able to perform requests via postaman on it.

Urls of attempts:

"http://localhost:5050 e http://0.0.0.0:5050"
"https://localhost:5001 e https://0.0.0.0:5001"
"http://localhost:5000 e http://0.0.0.0:5000"

Request:

{
  "UserName": "testeteste",
  "Name": "Teste Teste",
  "Email": "[email protected]",
  "Password": "Teste1234",
  "Password2": "Teste1234"
}

Repository: https://github.com/nicolabogar/Aplicacao-Gerenciar-Senhas

I set up a URL "http://0.0.0.0:5050" standard in Program.Cs

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)            
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseUrls("http://0.0.0.0:5050");
            webBuilder.UseStartup<Startup>();
            webBuilder.UseIISIntegration();
        })
        .UseContentRoot(Directory.GetCurrentDirectory())            
        .ConfigureAppConfiguration((builder, configuration) => 
        {                
            configuration.Sources.Clear();
            configuration.SetBasePath(Environment.CurrentDirectory);
            configuration.AddJsonFile("appsettings.json", true, true);
        });
}

I performed the appropriate settings in the Startup class

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAppSettings(Configuration);
        services.AddControllers();            
        services.AddSingletons();
        services.AddScopes();
        services.AddEntityFramework();
        services.AddAuthenticationJwt();
        
        services.AddLogging((config) =>
        {
            config.AddDebug();
            config.AddConsole();
        });

        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        
        app.UseHttpsRedirection();
        
        app.UseRouting();
        
        //app.UseAuthorization();
        //app.UseAuthentication();
        
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

1 answer

0

You must specify which controller is calling, you tried the following URL?

http://localhost:5050/api/Usuario/CriarUsuario
http://0.0.0.0:5050/api/Usuario/CriarUsuario

The UserUrls serves to:

Define it as a semicolon-separated list (;) of URL prefixes the server should respond to. For example, http://localhost:123. Use "" to indicate that the server must listen to requests at any IP address or host name using the specified port and protocol (e.g., http://:5000). The protocol (http:// or https://) must be included with each URL. Supported formats vary depending on the servers.

Source

Browser other questions tagged

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