En primer lugar, especifiqué la identificación real en la URL y luego definí el cuerpo. Desafortunadamente no funciona, recibí un código de error 400 del servidor.
Me gustaría agregar un nuevo jugador al club seleccionado. ¡Entonces mi solicitud de publicación está esperando una identificación y un cuerpo como parámetros!
Esta es mi solicitud de búsqueda de publicación que probé:
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); });
ACTUALIZAR
Este es el PlayerController en backend:
[HttpPost("{clubId}")] public void AddPlayerToClub(int clubId, [FromBody] Player player) { clubLogic.AddPlayerToClub(clubId, player); hub.Clients.All.SendAsync("PlayerCreated", player); }
La solicitud de publicación en el swagger: