<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Flaviu Tamasan</title>
    <description>The latest articles on DEV Community by Flaviu Tamasan (@rapmazzter).</description>
    <link>https://dev.to/rapmazzter</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F619819%2F0537df3f-f2ef-4c37-9bde-c423fae92f28.png</url>
      <title>DEV Community: Flaviu Tamasan</title>
      <link>https://dev.to/rapmazzter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rapmazzter"/>
    <language>en</language>
    <item>
      <title>Node JS POST Request including certificates and proxy configuration</title>
      <dc:creator>Flaviu Tamasan</dc:creator>
      <pubDate>Fri, 23 Apr 2021 18:58:36 +0000</pubDate>
      <link>https://dev.to/rapmazzter/node-js-post-request-including-certificates-and-proxy-configuration-1jml</link>
      <guid>https://dev.to/rapmazzter/node-js-post-request-including-certificates-and-proxy-configuration-1jml</guid>
      <description>&lt;p&gt;i have a special issue that i cannot fix. My setup is as follows:&lt;br&gt;
i want to make a POST request from behind a proxy using also certificates. I tried to use node-fetch or axios for this but axios has a defect when using a POST request and proxys and in node-fetch you only can use a proxy or the certificate as an agent, not both. Now i tried to use the node build in https module and wrote the following code (data is dummy):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const body = {}

const data = JSON.stringify(body)

const options = {
    host: proxy.host,
    port: proxy.port,
    path: 'https://server:port/path',
    method: 'POST',
    headers: {
        'Proxy-Authorization': auth,
        'Accept': 'application/json',
        'content-type': 'application/json',
        'requestid': 'ec69aa5d-52d8-4849-8b95-6e360f472860',
        'testid': '9b8183ed-967c-4701-bfa4-dd8c0ec6bab1',
    },
    key: fs.readFileSync('certificates/client.key.pem'),
    cert: fs.readFileSync('certificates/client.cert.pem'),
    agent: false
}

const req = https.request(options, (res) =&amp;gt; {
    console.log('statusCode:', res.statusCode);
    console.log('headers:', res.headers);

    res.on('data', (d) =&amp;gt; {
        process.stdout.write(d);
    });
});

req.write(data, () =&amp;gt; {
    console.log(req)
});
req.on('error', (e) =&amp;gt; {
    console.error(e);
});

req.end();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but this also does not work. It seams to me that the certificates are used for the proxy not for the actual URL in this case as i get the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: write EPROTO 4348:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16) {
  errno: 'EPROTO',
  code: 'EPROTO',
  syscall: 'write'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;triggering the request with CURL works with no problems. &lt;/p&gt;

&lt;p&gt;can you assist here somehow? Perhaps suggest another library that i can use for making this complex request?&lt;/p&gt;

&lt;p&gt;thanks,&lt;br&gt;
Flaviu&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>certificates</category>
      <category>proxy</category>
    </item>
  </channel>
</rss>
