Tag: unirest

节点npm Unirest给出陈旧/旧数据

我从我的节点js脚本中使用Unirest中间件来发出GET请求。 但由于某种原因,我正在从被请求的资源中获取陈旧/旧的数据。 即使在更新数据之后,我也从资源中获取陈旧的数据。 代码如下: let unirest = require('unirest'); unirest.get('<resource_url>') .headers({"cache-control": "no-cache"}) .end(function (response) { console.log('body===>',JSON.stringify(response.body)); console.log('status=====>',response.status); console.log('response headers=====>',response.headers); }); 响应标题===== {'strict-transport-security':'max-age = 15768000; includeSubDomains',date:'Fri,2017年9月15日18:58:40 GMT',cached_response:'true','cache-control':'no-transform,max-age = 3600',过期时间:'Fri,15 Sep 2017 12:10:53 GMT',变化:'接受,接受编码','内容长度':'1383',连接:'closures','内容types':'application / json','content-语言':'en-US'} 当通过Python scipt或CURL尝试时,相同的资源立即提供更新的数据。 注意:经过一段时间说3小时,节点js脚本提供更新的数据。

如何在nodejs中取消一个不太直接的请求

我有一个节点进程运行,不时地做一些unirest.get和unirest.post。 我也有一个Webterminaltypes,从中我可以看到所有不重要的请求的总体进度。 问题是我需要能够取消一个特定的请求,但我不知道如何。 结构是这样的: var requests = []; requests.push(unirest.post('someurl').end(somecallback)); requests.push(unirest.post('someurl').end(somecallback)); requests.push(unirest.post('someurl').end(somecallback)); 我想要做的事情如: requests[1].cancel(); // but of course this method doesn't exist 因为在这种情况下,我不能让callback触发,因为目标是取消它再次请求相同的URL,而不取消它的callback会触发两次。 任何人都知道如何取消/中断/销毁它?

使用最简单的库Node.js下载文件

我正在尝试使用Node的最简单的库下载文件。 这是我的代码到目前为止: unirest.get(url).end(function(res) { require("fs").writeFile(`${path}/app.zip`, res, "binary", (err) => { console.log(err); }); }); 但是,创build的zip文件不完整。 我也尝试过使用pipe道,但是没有任何保存。 可能是什么问题?

如何使用Unirest在NodeJS中POST JSON + pdf文件

在NodeJS中,我尝试使用以下代码将JSON数据和一个文件一起发布到服务器: unirest.post(url) .headers(headers) .send(data) .attach('file', file) .end(function (response) { var statusCode = response.status; if (statusCode != 200) { console.log("Result: ", response.error); } }); 但是,在服务器上,我只接收文件,而不是.send(data)的JSON对象。 我看到有一个.multipart()函数,我可以使用,但我不知道如何最好地使用它?

nodejs unirest post request – 如何发布复杂的rest / json主体

以下是我用来发布简单请求的最简单的代码。 urClient.post(url) .header('Content-Type', 'application/json') .header('Authorization', 'Bearer ' + token) .end( function (response) { }); 但是现在它需要发送一个复杂的json主体POST调用,如下所示: { "Key1": "Val1", "SectionArray1": [ { "Section1.1": { "Key2": "Val2", "Key3": "Val3" } } ], "SectionPart2": { "Section2.1": { "Section2.2": { "Key4": "Val4" } } } } 这怎么可能呢? 什么是适当的语法来做到这一点?