Tag: http

如何找出在Node.js中有多less连接的客户机到HTTP服务器?

假设我正在运行一个应用程序,该应用程序使用Express和Socket.io,都在Node http.Server的同一个实例上进行http.Server 。 每秒我都要login到控制台连接的客户端(HTTP或WS)的总数为监视目的。 setInterval(logConnectedClientInfo, 1000); 我怎样才能实现方法logConnectedClientInfo() ? 我知道我可以通过exec lsof来做到这一点,但我有兴趣,如果有一种方法可以在Node中做到这一点?

nodejs websocket和http基本authentication

我想在我的nodejs websocket应用程序中实现http基本身份validation身份validation。 这是我的一段代码: var http = require('http'); var auth = require('http-auth'); var express = require('express'); var app = express(); //…. basic = auth.basic({ realm: "websocket auth", file: __dirname + "/users.htpasswd" }); var server = http.createServer(basic); app.listen = function() { return server.listen.apply(server, arguments); }; // WEBSOCKET var WebSocketServer = require('websocket').server; var wss = new WebSocketServer({ httpServer: […]

在q-io / http.request上进行ETIMEDOUT

使用q-io / http拉入网页失败。 我想我一定会错过一些明显的东西 – 因为这是我认为是一个非常直接的例子。 编辑:Windows 8,节点11.13 var http = require('q-io/http') var url = 'http://www.google.com' ; http.request({ method: 'GET', uri: url }). then(function (response) { console.log(response) }). fail(function (err) { console.error(err) }); 这是输出: { state: 'pending' } > { [Error: connect ETIMEDOUT] stack: 'Error: connect ETIMEDOUT\n at exports._errnoException (util.js:742:11)\n at Object.afterConnect [as oncomplete] (net.js:989:19)', […]

使用Node下载.ttf文件

我试图用Node来下载一个.ttf文件。 我正在使用mikeal /请求来处理HTTP请求。 实际的function看起来像这样: request.get(url, function(err, res, body) { if(err) throw err; fs.writeFileSync(path, body); }); 匆匆一瞥后,它的行为完全如预期; 一切都结束在正确的地方,它看起来或多或less是正确的。 但是,当我尝试使用以下@font-face片段将字体加载到浏览器中时,该规则已应用,但字体不是。 没有错误,没有加载失败或被覆盖。 @font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 400; src: local('Open Sans'), local('OpenSans'), url(cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf) format('truetype'); } 对于初步检查,我试图用KFontView打开它,但遇到了“无法读取字体”错误。 我通过wgeting一个新的文件的副本来validation这个错误,并做同样的事情。 它加载到预览罚款。 这慢跑了我的记忆关于一个可以传递给writeFile的可选参数,所以我检查了wget版本和节点版本的编码。 $ enca wget.ttf -L none > Unrecognized Encoding $ enca node.ttf -L none > Universal transformation […]

我怎么能告诉我的NodeJS服务器哪个button被点击在一个HTTPforms与两个button?

我试图做一个NodeJS的Web应用程序,需要在文本框中的用户input,然后将它用于两个function(客户端)之一,基于哪个button被点击。 我可以吗 1)基于哪个button被点击或调用不同的动作 2)通过邮件正文区分两个button 我注意到,当按下不同的button时,我得到两个不同的响应console.log(req.body)与下面的代码。 当我点击提交button,我得到“{处理:'blahblahblah',hadunkachud:''}”当我点击新鲜的button,我得到“{处理:'blahblahblah',hingle:''}” 然而,我不能找出一种方法来访问响应的独特的部分,因为试图访问req.body的第二个数组值没有给我 下面的代码是在翡翠 extends layout block content h1= title form#formEnterHandle(name="enterhandle",method="post",action="/showid") input(type="text", placeholder="themirage", name="handle") button(name = "hadunkachud", type="submit") submit button(name = "hingle", type = "submit") fresh

节点api不返回数据给客户端ajax请求

我在Node.js中有一个非常基本的http服务器。 现在我只想返回一些JSON到一个浏览器做/ GET请求到一个特定的URL。 当我直接在浏览器(chrome)中直接访问本地主机地址时,我在“写入”方法中得到响应。 但是,我的骨干客户端中的ajax请求只是获取了200 OK头,但是当我打开开发工具时没有响应数据。 相当新的节点。 谁可以帮我这个事? 这是我的代码。 只是要分解它,我已经从JSON更改为文本/纯文本,并返回string“你好”。 res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('hello'); res.end();

我应该在收到304后closures代理连接吗?

我有一个HTTP请求/回应问题。 比方说,我有一个代理服务器,只是将客户端的请求转发给第三方服务器,第三方服务器的回应给客户端: var http = require('http'); var url = require('url'); http.createServer(function (req, res) { var opts = { hostname : 'www.example.com', port : 80, path : req.url, method : req.method, headers : req.headers }; opts.headers.host = opts.host; var proxyReq = http.request(opts, function (proxyResponse) { res.writeHead(proxyResponse.statusCode, proxyResponse.headers); proxyResponse.pipe(res); }); req.pipe(proxyReq); }).listen(3000); 假设客户端是caching感知的(比如浏览器),并且它传递了一个if-modified-since或者if-none-match (或者其他)头部,导致第三方服务器响应一个304状态码。 在技​​术上,服务器不应该发送一个正文,客户端在收到304之后不关心响应主体。 通过在服务器的代理响应处理程序中这样做是否有意义(并且会节省任何带宽/资源),这些服务器错误地使用304: var […]

节点JS通过URL发送数据

最近我开始用Node JS进行编程,发现它是一个惊人的php替代品。 在PHP中,我用来发送与URL中的数据请求。 类似于: http : //sample.com/public.php? x= helloworld 如何在Node JS中执行类似这样的事情,或者有没有更好的方法来发送数据到节点,而不像在上面的例子中使用url。 此外,我已经注意到,在某些情况下像stackoverflow,查询是不同的,不包括文件名 像/ public?=而不是/public.php?= 这是如何实现的,我一直认为这是与REST有关的东西。 另外,如果你有答案,你可以引导我,如果可以用Node来完成的话,一些学习资源也可以帮助你。

node.js HTTP服务器响应速度较慢,文件较小

我正在为node.js中的一个简单的HTTP服务器开发一个性能testing: var http = require('http'); var fs = require('fs'); var NO_CACHE = true; var fileCache; var sendFile = function(conn, file) { conn.writeHead(200, {'Content-Type': 'text/html', 'Content-Length': file.length}); conn.write(file); conn.end(); } http.createServer(function (req, res) { if (NO_CACHE || fileCache == undefined) { fs.readFile('index.html', function(err, file) { fileCache = file; sendFile(res, fileCache); }); } else { sendFile(res, fileCache); […]

当响应长度超过16101时,节点Js HTTP响应崩溃

我正在使用节点JS HTTP请求。 当我的回复长度超过16101时,它会截断我的回应。 我收到如下有限的回应: {"id_user":"133696"},{"id_u 这不是一个分块的回应,它只有一次。 我想接收整个响应而不是截断。 我的节点版本是v0.10.36。 这是我的代码: var https = require('https'); var querystring = require('querystring'); postData.format = 'json'; postData.apikey = 'abcd'; jsonObject = querystring.stringify(postData); var postheaders = { 'Content-Type' : 'application/x-www-form-urlencoded', 'Content-Length' : Buffer.byteLength(jsonObject, 'utf8') }; if(callMethod == undefined){ callMethod = 'POST'; } var optionspost = { host : this.host, port : this.port, […]