J'appelle une API pour télécharger le fichier Excel à partir du serveur en utilisant la récupération API, mais il n'a pas forcer le navigateur à télécharger, ci-dessous est ma réponse d'en-tête:Fetch API pour forcer le fichier de téléchargement
HTTP/1.1 200 OK Content-Length: 168667
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Server: Microsoft-IIS/8.5
Content-Disposition: attachment; filename=test.xlsx
Access-Control-Allow-Origin: http://localhost:9000
Access-Control-Allow-Credentials: true
Access-Control-Request-Method: POST,GET,PUT,DELETE,OPTIONS
Access-Control-Allow-Headers: X-Requested-With,Accept,Content-Type,Origin
Persistent-Auth: true
X-Powered-By: ASP.NET
Date: Wed, 24 May 2017 20:18:04 GMT
Ci-dessous mon code que j'utilise pour appeler l'API:
this.httpClient.fetch(url, {
method: 'POST',
body: JSON.stringify(object),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
Vous voudrez probablement utiliser https://stackoverflow.com/posts/44168090/edit pour mettre à jour/éditer votre question afin d'ajouter un extrait du code que vous utilisez pour essayer de télécharger le fichier – sideshowbarker
Comment appelez-vous API "? – Tom
this.httpClient.fetch (méthode URL, { \t: 'POST', \t corps: JSON.stringify (objet), \t têtes: { \t \t 'Accepter': 'application/json', \t \t 'Content-Type': 'application/json' \t} }) –