저는 현재 데이터 액세스를 위해 프런트 엔드에 Blazor를 사용하고 백 엔드에 ac # 웹 API를 사용하여 PoC (개념 증명) 애플리케이션을 작업하고 있습니다.
API에 액세스하고 싶을 때마다 ERR_CONNECTION_REFUSED가 표시됩니다. 나는 이상한 설정을 가지고 있습니다.
폴더 구조는 다음과 같습니다.
blazor_poc
API
컨트롤러
ApiRunningController.cs
BlazorApp
페이지
Index.razor
Index.razor에서 API를 호출해야합니다. 다음과 같이 API를 호출합니다.
protected override async Task OnInitializedAsync()
{
try
{
status = await Http.GetJsonAsync<string>("https://localhost:8394/ApiRunningController");
}
catch(Exception e)
{
requestSuccess = false;
status = "ERROR: " + e.Message;
}
}
이것이 API 구성의 모습입니다. launchSettings.json ( "api": {} 섹션 만 해당) :
"api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "apirunningcontroller",
"applicationUrl": "https://localhost:8394;http://localhost:8393",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Startup.cs의 내 ConfigureServices () 및 Configure () 메서드 :
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddCors();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseCors(c => c
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);
}
Api 컨트롤러 :
[ApiController]
[Route("[controller]")]
public class ApiRunningController : ControllerBase
{
// Some other code like initializing a logger in the constructor etc...
[HttpGet]
public string Get()
{
ApiModel model = new ApiModel();
return model.Status;
}
}
중요한 코드 스 니펫을 게시했다고 생각하는 많은 코드입니다. 내가 뭔가를 잊었다면 댓글을 남겨도 괜찮습니다. 가능한 한 빨리 게시하겠습니다.
사용자 솔루션 : sven-efftinge
포트 8394에 대한 번역 된 URL을 얻기 위해 콘솔에서 "gp url 8394"를 수행해야했습니다. 그런 다음 해당 URL을 HttpRequest에 사용해야했습니다.
protected override async Task OnInitializedAsync()
{
try
{
string translated_url = "https://8394-...gitpod.io/ApiRunningController"
status = await Http.GetJsonAsync<string>(translated_url);
}
catch(Exception e)
{
requestSuccess = false;
status = "ERROR: " + e.Message;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다