问题描述
然后我在Visual Studio中创建了新的api项目
我输入了命令httprepl
和cath错误
我完全是httprepl的新手,不明白为什么会收到该错误
任何运气...
请帮助我 新api项目中的一些代码
launchSettings.json
{
"$schema": "http://json.schemastore.org/launchsettings.json","iisSettings": {
"windowsAuthentication": false,"anonymousAuthentication": true,"iisExpress": {
"applicationUrl": "http://localhost:51685","sslPort": 44381
}
},"profiles": {
"IIS Express": {
"commandName": "IISExpress","launchbrowser": true,"launchUrl": "weatherforecast","environmentvariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},"Api2": {
"commandName": "Project","applicationUrl": "https://localhost:5001;http://localhost:5000","environmentvariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
我的Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Api2
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
appsetting.json
{
"Logging": {
"LogLevel": {
"Default": "information","Microsoft": "Warning","Microsoft.Hosting.Lifetime": "information"
}
}
}
WheatherForecastController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Api2.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing","Bracing","Chilly","Cool","Mild","Warm","Balmy","Hot","Sweltering","Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1,5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),TemperatureC = rng.Next(-20,55),Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}
解决方法
我今天在使用新的 .Net Core 5.0 解决方案时遇到了同样的问题。当我尝试从 git bash 窗口运行 httprepl https://localhost:5001
时,我收到了与您相同的消息。当我通过 Windows 命令提示符窗口运行 httprepl https://localhost:5001
时,它运行得很好。
也许您是从包管理器提示运行它的事实是您的问题。