Executing endpoint '405 HTTP Method Not Supported'

Discussão em 'Angular' iniciado por Tester, Março 31, 2025.

  1. Tester

    Tester Guest

    I'm developing an Angular application that communicates with an ASP.NET Core backend. When attempting to call the IsRequestValid endpoint from Angular, I receive a 405 HTTP Method Not Supported error. However, invoking the same endpoint via Swagger UI works as expected.

    Angular service method:

    @Injectable({ providedIn: 'root' })
    export class UserAppService {
    private apiUrl = '/weatherforecast';

    constructor(private http: HttpClient) { }

    isRequestValid(input: xxxUserDto): Observable\<xxxUserDto\> {
    const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
    return this.http.post\<xxxUserDto\>(`${this.apiUrl}/IsRequestValid`, input, { headers });
    }
    }


    Angular component method:

    this.userService.isRequestValid(this.UI_User)
    .pipe(
    catchError((error) =\> {
    this.toaster.error('Fehler beim Validieren des Tokens.');
    return throwError(() =\> error);
    })
    )
    .subscribe((response) =\> {
    this.UI_User = response;
    this.setCountDown();
    });


    Backend controller:

    \[ApiController\]
    \[Route("\[controller\]")\]
    public class WeatherForecastController : ControllerBase
    {
    // Constructor and other methods

    [HttpPost("IsRequestValid")]
    public async Task<ActionResult<xxxUserDto>> IsRequestValid([FromBody] xxxUserDto input)
    {
    // Method implementation
    }

    }


    Serilog output:

    2025-03-31 15:54:10.964 +02:00 \[INF\] Request starting HTTP/1.1 POST https://localhost:52288/weatherforecast/IsRequestValid - application/json 123
    2025-03-31 15:54:11.060 +02:00 \[INF\] Executing endpoint '405 HTTP Method Not Supported'
    2025-03-31 15:54:11.064 +02:00 \[INF\] Executed endpoint '405 HTTP Method Not Supported'


    Vite proxy error:

    15:57:02 \[vite\] http proxy error: /weatherforecast/IsRequestValid
    AggregateError \[ECONNREFUSED\]:
    at internalConnectMultiple (node:net:1139:18)
    at afterConnectMultiple (node:net:1712:7)


    What changes are necessary to successfully call the IsRequestValid endpoint from my Angular application without encountering the 405 error?

    Continue reading...

Compartilhe esta Página