Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 从post请求在磁盘上快速保存文件(gzip)_Xml_File_Express_Http_Request - Fatal编程技术网

Xml 从post请求在磁盘上快速保存文件(gzip)

Xml 从post请求在磁盘上快速保存文件(gzip),xml,file,express,http,request,Xml,File,Express,Http,Request,我尝试在post请求后保存文件,响应应该是xml文件,但它返回奇怪的数据 ��m~�'Z��O4B��M]�3.�οT��]G�s���rLM2��9�*��v�W/�Y����v����Z���4 我可以通过对话框从浏览器下载,但我无法通过后端将其保存为文件 const dataString = '0=0&1=1&2=2&3=3&4=4&5=5&6=6&7=7'; request({

我尝试在post请求后保存文件,响应应该是xml文件,但它返回奇怪的数据

��m~�'Z��O4B��M]�3.�οT��]G�s���rLM2��9�*��v�<代码>W/�Y����v����Z���4

我可以通过对话框从浏览器下载,但我无法通过后端将其保存为文件

        const dataString = '0=0&1=1&2=2&3=3&4=4&5=5&6=6&7=7';
        request({
            method: 'POST',
            uri: 'http://localhost:3000/template/d-thx-file/1498716378',
            headers: {
                'Connection': 'keep-alive',
                'Pragma': 'no-cache',
                'Cache-Control': 'no-cache',
                'Origin': 'http://localhost:3000',
                'Upgrade-Insecure-Requests': '1',
                'Content-Type': 'application/x-www-form-urlencoded',
                'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
                'Sec-Fetch-User': '?1',
                'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
                'Sec-Fetch-Site': 'same-origin',
                'Sec-Fetch-Mode': 'navigate',
                'Referer': 'http://localhost:3000/Produit.html',
                'Accept-Encoding': 'gzip, deflate, br',
                'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
            },
            resolveWithFullResponse: true, // optional, otherwise replace `res.body` with just `res` below
            gzip: true,
            encoding: null,
            body: dataString
        }).on('response', function (res, req, body) {
            res.pipe(fs.createWriteStream('./' + res.headers.date + '.' + res.headers['content-type'].split('/')[1], { encoding: 'utf8' }));
        });

我尝试了很多请求选项:gzip:true,encoding:null。。。但是没有任何效果

HTML只返回可读字符。请参阅Wiki:。GZIP还返回可读字符。所以你所做的工作奏效了。所以有两件事1)您没有xml 2)返回的字符与您使用的编码不同。您的数据看起来类似于另一个解密无法正常工作的帖子。您可能需要指定https而不是http。见张贴: