L'API (écrit en C#, ASP.NET de base) reçoivent 3 champs: titre, le contenu et un tableau de catégories (entiers):Envoyer tableau à l'API
[HttpGet]
[AllowAnonymous]
public IActionResult CreatePublication(string title, string content, IEnumerable<int> categoryIds)
{
return Ok();
}
Le problème est l'API reçoit toujours zéro éléments dans le tableau categoryIds.
Le client Angular4:
let ccategoryIds = new Array<number>()
ccategoryIds.push(2)
ccategoryIds.push(5)
ccategoryIds.push(7)
let requestOptions = {
params: new HttpParams()
.set('title', 'The title')
.append('content', 'The content')
.append('categoryIds', ccategoryIds.toString()),
withCredentials: true
}
this.http
.get('http://localhost:53203/api/publications/createPublication', requestOptions)
.subscribe(data => {
},
(err: HttpErrorResponse) => {
alert('Error')
})
Mise à jour
Si je JSON.stringify (ccategoryIds) au lieu de ccategoryIds.toString(), je reçois zéro éléments dans la API aussi.
Il est pas un problème du back-end. En Postman cela fonctionne:
@JohnDoe cette semble être un problème du côté C#. Pouvons-nous voir votre code là-bas? –