Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
For a fetch post request, how can I specify an id as a parameter?

First of all I specified the actual id in the url, and after that I defined the body. Unfortunately it doesn't work, I received a 400 error code back from the server.

I would like to add a new player to the selected club. So my post request is waiting for an id and a body as parameters!

This is my fetch post request which I tried:

fetch('https://localhost:44374/Player/' + selectedClub.clubId, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(
            {
                playerId: id,
                playerName: name,
                countryCode: code,
                playerCountry: country,
                playerBirthdate: birthdate,
                playerPosition: position,
                shirtNumber: shirtnumber,
                height: height,
                preferredFoot: preferredfoot,
                playerValue: value,
                clubId: selectedClub.clubId,
                club: selectedClub
            })})
        .then(response => response)
        .then(data => {
            console.log('Success:', data);
        })
        .catch((error) => { console.error('Error:', error); });

UPDATE

This is the PlayerController in backend:

[HttpPost("{clubId}")]
public void AddPlayerToClub(int clubId, [FromBody] Player player)
{
     clubLogic.AddPlayerToClub(clubId, player);
     hub.Clients.All.SendAsync("PlayerCreated", player);
}

The post request in the swagger:

IMAGE

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda