SOLVED - Downloading a file via httpClient is corrupted

I am trying to use httpClient to post form data and then get back an excel file.

I have verified via http that the file is a valid excel file, but when I try to read the file, I only get the printed headers from the response.

javascript code:

        const self = this;

        var url = 'http://[ipaddress]/';
        var formData = new FormData(document.forms['searchform']);

        formData.append('REMOTE_USER', self.user);
        formData.append('excel', 'open');
        formData.append('wltype', this.state.searchObj.wlTypeRadio);
        formData.append('agingStyle', this.state.searchObj.agingStyleRadio);
        formData.append('custBal', this.state.searchObj.custBalRadio);
        formData.append('MODE', this.state.searchObj.mode);

        if (typeof(this.state.searchObj.potentialBadDebtRadio) != undefined &&
            this.state.searchObj.potentialBadDebtRadio != null)
        var filename = this.user + '-';

        var dformat;

        var d = new Date();

        var  dformat = [d.getFullYear(), (d.getMonth()+1).toString().padStart(2,'0'),
            d.getDate().toString().padStart(2,'0')].join('') +'-' +
        filename += dformat + '.xlsx';
        console.log('filename', filename);
        return self.httpClient
        .fetch(url, {
            body: formData,
            method: 'POST'
        .then(async (response) => response.blob())
        .then((blob) => 
            download(blob, filename, mime.getType(filename)));

Verify what response you get with a tool such as Chrome Developer tab och Fiddler. You must first verify that the response actually is what you think it is.

I solved the problem late last night.

I was printing the wrong headers, so it was garbling the excel file.

When I printed the content-type as, it fixed everything, and now it’s downloading.