node.js http:创建到主机的持久连接,并将请求发送到多个路径
我想创建到主机(api.development.push.apple.com)的持久http连接,并发送许多路径的POST请求 (例如,'/3/device/1'、'/3/device/2'等)。下面的代码会为每个http.request()创建一个主机连接还是多个连接node.js http:创建到主机的持久连接,并将请求发送到多个路径,node.js,http,Node.js,Http,我想创建到主机(api.development.push.apple.com)的持久http连接,并发送许多路径的POST请求 (例如,'/3/device/1'、'/3/device/2'等)。下面的代码会为每个http.request()创建一个主机连接还是多个连接 您希望对所有请求使用相同的代理 如果未在options对象中指定代理,http模块将使用globalAgent,默认情况下将keepAlive设置为false 因此,创建代理,并将其用于所有请求: var http = requ
您希望对所有请求使用相同的代理 如果未在options对象中指定代理,http模块将使用globalAgent,默认情况下将keepAlive设置为false 因此,创建代理,并将其用于所有请求:
var http = require('http');
var agent = new http.Agent({ keepAlive: true }); // false by default
http.request({
host: 'api.development.push.apple.com',
port: 443,
path: '/3/device/1',
method: 'POST',
agent: agent, // use this agent for more requests as needed
}).end();
您是否知道服务器代码需要做哪些更改才能正常工作?我希望对response.end()的调用进行映像处理会很糟糕吗?
var http = require('http');
var agent = new http.Agent({ keepAlive: true }); // false by default
http.request({
host: 'api.development.push.apple.com',
port: 443,
path: '/3/device/1',
method: 'POST',
agent: agent, // use this agent for more requests as needed
}).end();