Tag: httprequest

Node.js`“http.get”不会返回给浏览器的完整响应体,而只是一个<head>标记。 如何得到完整的回应?

我遇到了Node.js http.get一个奇怪的行为。 我向ajax发送一个请求,并且想把结果传到我的浏览器中。 但是我只能得到一些<head>标签内容,没有其他内容。 但是,如果我将结果发送到系统控制台( console.log(chunk) ),我得到的结果,因为我想得到 – 整个页面。 这是我的步骤: // Simple jQuery Ajax GET $.ajax({ type: "GET", url: "/myapppath", // send to my app's url data: {foo: "bar"}, success: onLoad, // the callback, see just bellow error: onError, dataType: "text" }); // With this callback function I want to insert the result into <div […]

用Node.js /强大的中止用户请求

我正在使用强大的接收与node.jsfile upload。 我在一个多部分请求中将一些字段与一个文件一起发送。 只要某些字段到达,我就可以validation请求的真实性,如果不正确,我想中止整个请求,以避免资源浪费。 我还没有find正确的方法来中止传入的请求。 我试图使用req.connection.destroy(); 如下: form .on('field', function(field, value) { fields[field] = value; if (!fields['token'] || !fields['id'] || !fields['timestamp']) { return; } if (!validateToken(fields['token'], fields['id'], fields['timestamp'])) { res.writeHead(401, {'Content-Type' : 'text/plain' }); res.end('Unauthorized'); req.connection.destroy(); } }) 但是,这会触发以下错误: events.js:45 throw arguments[1]; // Unhandled 'error' event ^ Error: Cannot resume() closed Socket. at Socket.resume (net.js:764:11) […]

HTTP请求node.js使用mikeal的“请求”

我正在尝试使用https://github.com/mikeal/request 。 我的代码有什么问题? 错误消息在代码中。 在我的程序中,我正在使用我的真实App和Rest ID var request = require('request'); request.post( { url: 'https://api.parse.com/1/classes/GameScore', headers: { "X-Parse-Application-Id": "11111", "X-Parse-REST-API-Key": "222222", "Content-Type": "application/json" }, body: { "score": 1337, "playerName": "Sean Plott", "cheatMode": false } }, function (error, response, body) { if(response.statusCode == 201){ console.log('Status Update'); } else { console.log('error: '+ response.statusCode); console.log(body); } } ); 错误信息: […]

Node.js请求获取ETIMEDOUT和ESOCKETTIMEDOUT的模块

我正在爬取与请求模块的许多链接与asynchronous模块的组合并行。 我注意到ETIMEDOUT和ESOCKETTIMEDOUT错误的很多,虽然链接是可及的,并且使用chrome快速响应。 我已经将请求选项中的maxSockets限制为2, timeout为10000。 我使用限制为2的async.filterLimit() ,每次甚至将并行性降低到2个请求。 所以我有2个套接字,2个请求,10秒的超时等待从服务器的标题响应,但我得到这些错误。 这里的请求configuration我使用: { … pool: { maxSockets: 2 }, timeout: 10000 , time: true … } 以下是我用于fecth链接的代码片段: var self = this; async.filterLimit(resources, 2, function(resource, callback) { request({ uri: resource.uri }, function (error, response, body) { if (!error && response.statusCode === 200) { … } else { self.emit('error', resource, error); […]

node.js – 请求 – 如何“emitter.setMaxListeners()”?

当我使用node.js'request'模块对某个URI进行GET时, var options = {uri:"aURI", headers:headerData}; request.get(options, function (error, response, body) { } 错误消息是: [Error: Exceeded maxRedirects. Probably stuck in a redirect loop.] 还有以下消息: "(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit." 我如何设置setMaxListeners ?