当我向 google api 发送请求时(使用 axios 或仅使用 https),例如https://www.googleapis.com/blogger/v3/blogs/2399953?key=...
我总是点击“在建立安全 TLS 连接之前,客户端网络套接字已断开连接" error.
但是如果我发送请求到https://api.github.com https://api.github.com,它工作得很好。我已经用谷歌搜索了该错误,但找不到太多有用的信息。这里https://github.com/nodejs/node/issues/21088 https://github.com/nodejs/node/issues/21088说如果服务器使用 TLS 1.0,它可能会发生,但显然这不是我的情况。
我也尝试谷歌API https://www.npmjs.com/package/googleapis但仍然遇到同样的错误。
知道如何修复错误吗?
- - 更新 - -
我的问题已于 5 个月前结束。我打开了an issue https://github.com/googleapis/google-api-nodejs-client/issues/1471针对googleapi,它也被关闭了。我已经放弃了它,但令我惊讶的是它不断获得流量。所以我更新了我的问题并希望它能重新开放。
首先,google api已经移到这里了https://github.com/googleapis/google-api-nodejs-client https://github.com/googleapis/google-api-nodejs-client
二、只用vpn来运行第一个例子 https://github.com/googleapis/google-api-nodejs-client#first-example在那里(使用VPN,因为谷歌服务因某种原因被阻止),我将获得连接ETIMEDOUT,同时我可以从浏览器获取结果。
const {google} = require('googleapis');
const blogger = google.blogger({
version: 'v3',
auth: 'YOUR API KEY'
});
blogger.blogs.get({blogId: '3213900'}, (err, res) => {
if (err) {
console.error(err);
throw err;
}
console.log(`The blog url is ${res.data.url}`);
});
//But I can get result in browser https://blogger.googleapis.com/v3/blogs/3213900?key=xxx
我认为问题是可以解决的,因为 nodejs 不通过我的 VPN 代理发送请求。所以我的问题与这个有点相关,当 URL 在浏览器中运行时,什么可能导致“connect ETIMEDOUT”错误? https://stackoverflow.com/questions/33350604/what-could-cause-connect-etimedout-error-when-the-url-is-working-in-browser
但那里的解决方案对我不起作用。这个SO中的一个答案如何将 http 代理与 node.js http.Client 一起使用? https://stackoverflow.com/questions/3862813/how-can-i-use-an-http-proxy-with-node-js-http-client提到使用request https://github.com/request/request它有效!
var request = require("request");
request(
{
url:
"https://blogger.googleapis.com/v3/blogs/3213900?key=xxx",
method: "GET",
proxy: my-vpn-proxy,
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
太糟糕了,请求被否决了!我也无法让 axios 工作!
我也尝试过tunnel https://www.npmjs.com/package/tunnel并得到了read ECONNRESET error
;我试过全局隧道 NG https://www.npmjs.com/package/global-tunnel-ng并得到错误
TypeError: Cannot read property 'proxy' of undefined
But https 代理代理 https://www.npmjs.com/package/https-proxy-agent也有效,
var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');
// HTTP/HTTPS proxy to connect to
var proxy = 'my-vpn-proxy';
var endpoint = 'https://blogger.googleapis.com/v3/blogs/3213900?key=xxx';
var opts = url.parse(endpoint);
var agent = new HttpsProxyAgent(proxy);
opts.agent = agent;
https.get(opts, function (res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
所以我认为这个问题可能是可以解决的。