title: "Client network socket disconnected before secure TLS connection was established", node 10
body: <p>When I send request to google api (using either axios or just https), e.g. <code>https://www.googleapis.com/blogger/v3/blogs/2399953?key=...</code></p>
  <p>I always hit the &quot;<strong>Client network socket disconnected before secure TLS connection was established</strong>&quot; error.</p>
  <p>But if I send request to <a href="https://api.github.com" rel="noreferrer">https://api.github.com</a>, it works just fine. I have googled the error, but I can't find much useful information.  Here <a href="https://github.com/nodejs/node/issues/21088" rel="noreferrer">https://github.com/nodejs/node/issues/21088</a> said if the server uses TLS 1.0, it may happen but apparently it is not my case.</p>
  <p>I also try <a href="https://www.npmjs.com/package/googleapis" rel="noreferrer">googleapis</a> but still hit the same error.</p>
  <p>Any idea how to fix the error ?</p>
  <p>---- update ----</p>
  <p>My question was closed 5 months ago. I opened <a href="https://github.com/googleapis/google-api-nodejs-client/issues/1471" rel="noreferrer">an issue</a> against googleapi and it was also closed. I had gave it up but to my surprise it keeps getting traffic. So I updated my question and hope it will be reopened.</p>
  <p>First, google api has moved to here <a href="https://github.com/googleapis/google-api-nodejs-client" rel="noreferrer">https://github.com/googleapis/google-api-nodejs-client</a></p>
  <p>Second, just using vpn to run <a href="https://github.com/googleapis/google-api-nodejs-client#first-example" rel="noreferrer">the first example</a> there (using vpn because google service is blocked for whatever reason), I will get connect ETIMEDOUT while I can get the result from browser.</p>
  <pre><code>const {google} = require('googleapis');
  const blogger = google.blogger({
    version: 'v3',
    auth: 'YOUR API KEY'
  });
  
  blogger.blogs.get({blogId: '3213900'}, (err, res) =&gt; {
    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
  </code></pre>
  <p>I think the problem was solvable because nodejs doesn't send the request through my vpn proxy. So my question is somewhat related to this one, <a href="https://stackoverflow.com/questions/33350604/what-could-cause-connect-etimedout-error-when-the-url-is-working-in-browser">What could cause &quot;connect ETIMEDOUT&quot; error when the URL is working in browser?</a></p>
  <p>But the solution there did not work for me. One answer in this  SO <a href="https://stackoverflow.com/questions/3862813/how-can-i-use-an-http-proxy-with-node-js-http-client">How can I use an http proxy with node.js http.Client?</a> mentioned using <a href="https://github.com/request/request" rel="noreferrer">request</a> and it works!</p>
  <pre><code>var request = require(&quot;request&quot;);
  
  request(
    {
      url:
        &quot;https://blogger.googleapis.com/v3/blogs/3213900?key=xxx&quot;,
      method: &quot;GET&quot;,
      proxy: my-vpn-proxy,
    },
    function (error, response, body) {
      if (!error &amp;&amp; response.statusCode == 200) {
        console.log(body);
      }
    }
  );
  </code></pre>
  <p>Too bad request was deprecated! I can't make axios works too!</p>
  <p>I also tried <a href="https://www.npmjs.com/package/tunnel" rel="noreferrer">tunnel</a> and got <code>read ECONNRESET error</code>; I tried <a href="https://www.npmjs.com/package/global-tunnel-ng" rel="noreferrer">global-tunnel-ng</a> and got the error</p>
  <pre><code>TypeError: Cannot read property 'proxy' of undefined
      
  </code></pre>
  <p>But <a href="https://www.npmjs.com/package/https-proxy-agent" rel="noreferrer">https-proxy-agent</a> works too,</p>
  <pre><code>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('&quot;response&quot; event!', res.headers);
    res.pipe(process.stdout);
  });
  </code></pre>
  <p>So I think this problem may be solvable.</p>