Tag: 获取

Axios GET请求不起作用

我正在使用:Axios:0.17.1节点:8.0.0 以下标准节点得到正常工作,但Axios版本没有。 任何想法为什么? 节点http: http .get(`${someUrl}`, response => { buildResponse(response).then(results => res.send(results)); }) .on('error', e => { console.error(`Got error: ${e.message}`); }); 爱可信: axios .get(`${someUrl}`) .then(function(response) { buildResponse(response).then(results => res.send(results)); }) .catch(function(error) { handleError(error, res); }); 我只是得到一个503的捕获,“请求失败,状态码503”

如何发送cookie与节点获取?

我有nodejs应用程序,它处理用户的请求,并接收我想代理内部API服务的cookie。 如何通过使用节点获取? 请不要提供superagent。

Chrome浏览器/火狐浏览器发送两个邮件正好5秒钟,只有一个调用来获取Nodejs 8.0.0服务器

注:这不是预检选项,它不是favicon或任何其他类似的。 这实际上是2 POSTS。 下面有一个截图,更清晰地显示出来。 我的规格/版本: macOS Sierra版本10.12.3 Chrome版本61.0.3128.0(官方版本)dev(64位) 节点v8.0.0 我有一个服务器,使用setTimeout等待10秒后才响应。 我有一个前端,使单个POST到服务器。 使用wireshark,我可以看到浏览器实际上做了2个POST,第二个在t + 5s。 服务器看到这两个POST并对两者都响应。 前端只能得到第二个POST的结果。 在下面的示例中,您将看到,获取实际需要15秒才能完成,而不是您希望从服务器中超时的10秒。 该呼叫是CORS,只有当服务器花费超过5秒的时间来响应时才会发生。 这里发生了什么,我该如何阻止它呢? 这是一个最小的复制: server.js(与节点一起运行) var http = require("http"); // A counter for the requests var counter = 0; var server = http.createServer(function(request, response) { // Closure to prevent the request number from changing with the counter. (function(requestNumber) { […]

使用fetch-mock模拟zip压缩响应

我试着用下面的代码: require( 'isomorphic-fetch' ); const fetchMock = require( 'fetch-mock' ), fsp = require( 'fs-promise' ), unzip = require( 'unzip' ), rimraf = require( 'rimraf-then' ), path = require( 'path' ); let zipLink = 'https://github.com/stevemao/left-pad/archive/master.zip', out = 'left-pad-master'; // Careful: lib might be removed at any moment. fetchMock.get( zipLink, fsp.createReadStream( path.join( __dirname, 'left-pad-master.zip' ) ) ); […]

在页面加载时骨干提取集合

我知道backbone文档说fetch不应该被用来在页面加载时填充集合 ,而且我会弄清楚为什么: var appCollection = Backbone.Collection.extend({ model:appModel, url:'api/app', initialize:function(){ this.fetch(); }, }); var homeView = Backbone.View.extend({ el:'#content', initialize:function(){ this.collection = new appCollection(appModel) this.render() }, render: function () { var that = this; alert(1); _.each(this.collection.models, function (item) { that.renderApp(item); }, this); }, renderApp: function (item) { var appview = new appView({ model: item }); this.$el.append(appview.render().el); } […]

在Node.js中向JSON API发出GET请求?

想知道如何使用Node.js对一个JSON API做一个GET请求。 我最好想使用Express,但是这不是必须的,输出在Jade页面上。 对于Node.js和后端语言,我还是一个全新的东西。

当jsonparsing一个空的响应时,Whatwg Fetch失败,我该如何防止它?

我在前端和后端(NodeJS)都使用了Fetch API,这个问题在将响应parsing为json时会遇到很多问题。 response.json()将返回一个promise,所以我不知道响应的主体是什么,当body是空的时候,JSONparsing将会失败并显示错误: SyntaxError: Unexpected end of input 所以我的问题是,如何防止parsing响应时,它的空? 谢谢

Node.js:使用多个查询参数来表示app.get

我想查询yelp API,并有以下路线: app.get("/yelp/term/:term/location/:location", yelp.listPlaces) 当我向GET请求时 http://localhost:3000/yelp?term=food&location=austin , 我得到错误 Cannot GET /yelp?term=food&location=austin 我究竟做错了什么?

Node.js:node.js中的http.get方法是否有同步版本?

node.js中有没有同步版本的http.get方法? 就像是: http.getSync({ host: 'google.com', port: 80, path: '/' }, function(response){ }); console.log(response) 有时候这会非常有用。

Koa的`ctx.status`没有被发送到客户端

这是我的简单路线: router.post('/getFile', async (ctx) => { const fileName = `${ctx.request.body.file}.pdf`; const file = fs.createReadStream(fileName); // This file might not exist. file.on('error', (err) => { ctx.response.status = 500; // This status code doesn't make it to client when there's an error. }); ctx.response.type = 'application/pdf'; ctx.response.body = file; }); 这里是我的客户代码: async function main() { const request […]