- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在执行 GET 请求时遇到错误。
Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
当我尝试向 https://www.adidas.co.uk/api/search/taxonomy?query=men
发出 GET 请求时会发生这种情况,但当我使用 时它会起作用https://jsonplaceholder.typicode.com/api/todos/1
.
要求:
var request = require('request');
[...]
app.use('/api', cacheMiddleware(), function (req, out) {
var headers = {
//'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
'Content-Type': 'application/x-www-form-urlencoded'
//'Content-Type': 'application/jsond'
};
var url = getDestinationUrl(req);
if (req.method === 'POST') {
console.log('POST body:')
console.log(req.body);
result = request.post({ uri: url, json: req.body, headers: headers, followRedirect: true , maxRedirects: 10}, function (error, response, body) { handleResponse(req, out, error, response, body) });
} else {
result = request({ uri: url, headers: headers, followRedirect: true, maxRedirects: 10 }, function (error, response, body) { handleResponse(req, out, error, response, body) });
}
});
日志:
handle https://www.adidas.co.uk/api/search/taxonomy?query=men
REQUEST { uri: 'https://www.adidas.co.uk/api/search/taxonomy?query=men',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
followRedirect: true,
maxRedirects: 10,
callback: [Function] }
HTTP 10384: SERVER socketOnParserExecute 739
REQUEST make request https://www.adidas.co.uk/api/search/taxonomy?query=men
HTTP 10384: call onSocket 0 0
HTTP 10384: createConnection www.adidas.co.uk:443:::::::::::::::: { servername: 'www.adidas.co.uk',
_defaultAgent:
Agent {
_events: [Object: null prototype] { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
sockets: { 'www.adidas.co.uk:443::::::::::::::::': [] },
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: { map: {}, list: [] } },
_events:
[Object: null prototype] {
error: [Function: bound ],
complete: [Function: bound ],
pipe: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
uri:
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'www.adidas.co.uk',
port: 443,
hostname: 'www.adidas.co.uk',
hash: null,
search: '?query=men',
query: 'query=men',
pathname: '/api/search/taxonomy',
path: '/api/search/taxonomy?query=men',
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded',
host: 'www.adidas.co.uk' },
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs:
Querystring {
request:
Request {
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
uri: [Url],
headers: [Object],
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs: [Circular],
_auth: [Auth],
_oauth: [OAuth],
_multipart: [Multipart],
_redirect: [Redirect],
_tunnel: [Tunnel],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: '/api/search/taxonomy?query=men',
httpModule: [Object],
agentClass: [Function],
agent: [Agent],
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
lib:
{ formats: [Object], parse: [Function], stringify: [Function] },
useQuerystring: undefined,
parseOptions: {},
stringifyOptions: {} },
_auth:
Auth {
request:
Request {
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
uri: [Url],
headers: [Object],
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs: [Querystring],
_auth: [Circular],
_oauth: [OAuth],
_multipart: [Multipart],
_redirect: [Redirect],
_tunnel: [Tunnel],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: '/api/search/taxonomy?query=men',
httpModule: [Object],
agentClass: [Function],
agent: [Agent],
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
hasAuth: false,
sentAuth: false,
bearerToken: null,
user: null,
pass: null },
_oauth:
OAuth {
request:
Request {
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
uri: [Url],
headers: [Object],
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs: [Querystring],
_auth: [Auth],
_oauth: [Circular],
_multipart: [Multipart],
_redirect: [Redirect],
_tunnel: [Tunnel],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: '/api/search/taxonomy?query=men',
httpModule: [Object],
agentClass: [Function],
agent: [Agent],
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
params: null },
_multipart:
Multipart {
request:
Request {
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
uri: [Url],
headers: [Object],
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs: [Querystring],
_auth: [Auth],
_oauth: [OAuth],
_multipart: [Circular],
_redirect: [Redirect],
_tunnel: [Tunnel],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: '/api/search/taxonomy?query=men',
httpModule: [Object],
agentClass: [Function],
agent: [Agent],
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
boundary: '54c4df7c-a16d-45e6-a57b-bb7f83e6b1fa',
chunked: false,
body: null },
_redirect:
Redirect {
request:
Request {
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
uri: [Url],
headers: [Object],
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs: [Querystring],
_auth: [Auth],
_oauth: [OAuth],
_multipart: [Multipart],
_redirect: [Circular],
_tunnel: [Tunnel],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: '/api/search/taxonomy?query=men',
httpModule: [Object],
agentClass: [Function],
agent: [Agent],
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
followRedirect: true,
followRedirects: true,
followAllRedirects: false,
followOriginalHttpMethod: false,
allowRedirect: [Function],
maxRedirects: 10,
redirects: [],
redirectsFollowed: 0,
removeRefererHeader: false },
_tunnel:
Tunnel {
request:
Request {
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
uri: [Url],
headers: [Object],
followRedirect: true,
maxRedirects: 10,
callback: [Function],
readable: true,
writable: true,
_qs: [Querystring],
_auth: [Auth],
_oauth: [OAuth],
_multipart: [Multipart],
_redirect: [Redirect],
_tunnel: [Circular],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: '/api/search/taxonomy?query=men',
httpModule: [Object],
agentClass: [Function],
agent: [Agent],
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men' },
proxyHeaderWhiteList:
[ 'accept',
'accept-charset',
'accept-encoding',
'accept-language',
'accept-ranges',
'cache-control',
'content-encoding',
'content-language',
'content-location',
'content-md5',
'content-range',
'content-type',
'connection',
'date',
'expect',
'max-forwards',
'pragma',
'referer',
'te',
'user-agent',
'via' ],
proxyHeaderExclusiveList: [] },
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
method: 'GET',
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'www.adidas.co.uk',
path: null,
httpModule:
{ Agent: { [Function: Agent] super_: [Function] },
globalAgent:
Agent {
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: [Object] },
Server: { [Function: Server] super_: [Function] },
createServer: [Function: createServer],
get: [Function: get],
request: [Function: request] },
agentClass:
{ [Function: Agent]
super_:
{ [Function: Agent] super_: [Function], defaultMaxSockets: Infinity } },
agent:
Agent {
_events: [Object: null prototype] { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
sockets: { 'www.adidas.co.uk:443::::::::::::::::': [] },
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: { map: {}, list: [] } },
_started: true,
href: 'https://www.adidas.co.uk/api/search/taxonomy?query=men',
_agentKey: 'www.adidas.co.uk:443::::::::::::::::' }
HTTP 10384: sockets www.adidas.co.uk:443:::::::::::::::: 1
HTTP 10384: outgoing message end.
HTTP 10384: SOCKET ERROR: read ECONNRESET Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27)
handleResponse...
Response error
{ Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
HTTP 10384: outgoing message end.
HTTP 10384: CLIENT socket onClose
HTTP 10384: removeSocket www.adidas.co.uk:443:::::::::::::::: writable: false
HTTP 10384: HTTP socket close
HTTP 10384: server socket close
更新:它适用于 axios:
app.use('/api', cacheMiddleware(), function (req, out) {
var url = getDestinationUrl(req);
if (req.method === 'POST') {
axios.post(url, req.body)
.then(response => {
handleResponse(req, out, response, response.data)
})
.catch(error => {
handleResponseError(req, out, error)
});
} else {
axios.get(url)
.then(response => {
handleResponse(req, out, response, response.data)
})
.catch(error => {
handleResponseError(req, out, error)
});
}
});
最佳答案
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection.
此错误仅表示另一方以可能不正常(或可能很匆忙)的方式关闭了连接。
一个例子是:一个套接字连接可能由于多种原因被对方突然关闭,或者您在运行您的应用程序时丢失了 wifi 信号。然后你会在你这边看到这个错误/异常。
解决方案- 发生这种情况是因为您没有监听/处理“错误”事件,要处理它,您应该放置一个可以处理此类错误的监听器。
它在 Axios 中工作,因为您正在使用 promises 进行异步错误处理。
关于node.js - NodeJs ECONNRESET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53912439/
我的 React 项目需要更新 nodejs。那么我如何将我的 Node js 重新安装到 Ubuntu 16.04 中的最新版本。 我当前的 Node 版本是 node -v v6.0.0 我当前的
我正在寻找逐步调试 NodeJS 服务器代码的有效方法。目前我使用了几十个console.log(),这非常困难。完美的工具可以让我检查堆栈中每个变量的值并逐行跟踪我的程序。首选操作系统 = MacO
我的网站上有以下两个文件: firebase.js gridsome-server.js firebase.js 是一个“常规”javascript 文件,包含以下内容: import firebas
我有一个nodejs应用程序从文件夹A执行,二进制X也在文件夹A中执行(使用子进程exec)。二进制 X 在文件夹 A 中生成输出文件 O,因此始终从调用位置开始。 我需要nodejs应用程序来在仲裁
我有以下nodeJS服务器,它似乎工作正常。我想编写一个客户端,从服务器接收消息并根据消息调用一些 JS。 涉及的步骤是: 用户访问网址http://server.xyz.com:8080/pa no
我想从 Node 服务器进行其余 api 调用。我目前脑子里有请求模块。 您是否会建议用于 Nodejs 中生产实践的 REST 调用(get/post)的任何其他最佳模块? 问候,公羊 最佳答案 R
我正在尝试像这样使用 mainModule: const { mainModule } = require('process'); module.exports = path.dirname(main
我现在对那些版本号真的很困惑。我正在计划一个新项目,想知道这两个版本之间有什么区别。这两个版本之间似乎有很大的跳跃,但现在我找不到区别。 使用 4.1 版安全吗? 感谢您的帮助! 最佳答案 跳转到 v
我试图找到我的问题的解决方案,但找不到,并且正在寻找一些“最佳实践示例”。我有一个 nodejs express 应用程序,我的函数在文件中拆分。例如我有这个 Controller (oktacont
这看起来像是一个非常简单的问题,但作为一个 JS 初学者,我想知道是否可以在 webextension 中使用 NodeJS 模块(例如我想使用这个:https://github.com/yaronn
我有一个文件。a.js class A{ constructor(name){ this.name = name; } displayName(){ conso
我想做的是这样的: node x.js | node y.js 文件 x.js 只是打印一个字符串: console.log("hi"); 文件 y.js 旨在通过 process.stdin 获取字
对于这个新的nodejs debugger I am working on我想对显示的源代码行进行着色。有什么关于 npm 使用的建议吗? 有很多语法荧光笔,但使这种情况有点不同的是 输出是到终端;它
有没有什么方法可以从 ejs View 中引用包含在 node_modules 文件夹中的 Nodejs 库? 我正在使用 expressjs 并且我的客户端库由 /public 文件夹提供,如下所示
我是 NodeJS 的新手,我正在尝试根据 NodeJS 站点上的指南在 NodeJS 中创建一个服务器。我已经在我的电脑上安装了 NodeJS 并使用以下代码制作了 app.js 文件。 const
我有一个 nodejs-express 服务器 (1) 与 mongodb 通信,还有一个 web 服务器 (2) 在 nodejs-express 和 Angularjs 中。我正在尝试发出 pos
我一直在解决(firebase 和 nodejs)问题,这是该问题的第四部分,如何在登录到 server.js 后传递数据 我已经尝试过this但未能使其正常工作。 基本上,我正在尝试将用户idTok
每次页面刷新时,NodeJS 都会在套接字上多次写入数据。当我刷新页面时,nodejs 服务器写入套接字的计数增加,在多个页面刷新时,写入计数固定为 3。 请检查控制台输出是否有此奇怪的响应。请提出同
我在尝试更新文件夹并再次部署其内容时遇到问题。我必须使用 NodeJS 并已获得端口 8080 来使用。我尝试创建一个 php 脚本(update.php): 现在我想启动NodeJS脚本进行更新,
我不明白java多线程系统和Nodejs多线程系统在性能和资源共享方面的区别。由于 NodeJS 为您的程序使用事件循环单线程,但在幕后,它将任务分配给不同的线程,如文件读取或数据库查询。所以它使用多
我是一名优秀的程序员,十分优秀!