node.js - Send GET request with pfx file using AXIOS failed - Stack Overflow

时间: 2025-01-06 admin 业界

Send GET request did not return correct response. But accessing API via browser returns correctly.

Basically, I use AXIOS to send GET request to an API to get response. As expect, it should return this: <Authentication>AccessGranted</Authentication>, and accessing given URL in browser works fine.

My code is below:

const axios = require("axios");
const https = require("https");const fs = require("fs");
const pfxPath ="C:\Users\RYANHUYNHPC\Downloads\connection.pfx";
const pfxPassword = "connectPassword123";

console.log(pfxPath);

const httpsAgent = new https.Agent({

   pfx: fs.readFileSync(pfxPath),
   passphrase: pfxPassword,
   minVersion: "TLSv1.3", // Enforce TLS 1.3});

async function sendGetRequest() {
   const url =".aspx?Page=Login&Mode=Silent&UserID=testuser01&Password=testuser01pw";

try {
    const response = await axios.get(url, {
         httpsAgent,
         withCredentials: true, // Enable cookies});
    console.log("Headers:", response.headers);
    console.log("Status Code:", response.status);
    console.log("GET Response:", response.data);
} catch (error) {
    console.error("GET Error:",error.response ? error.response.data : error.message);}
}

(async function main() {
    console.log("Sending GET request...");
    await sendGetRequest();})();

After run, it returns:

Sending GET request...Headers: Object [AxiosHeaders] {server: 'BigIP','content-type': 'text/html; charset=utf-8','accept-ranges': 'bytes',connection: 'Keep-Alive',date: 'Wed, 18 Dec 2024 19:19:44 GMT',age: '33931','x-frame-options': 'DENY','set-cookie': ['MRHSession=deleted;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;secure','F5_ST=deleted;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;secure','MRHSHint=deleted;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;secure','F5_HT_shrinked=deleted;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;secure','F5_fullWT=deleted;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;secure','MRHSequence=deleted;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;secure','visid_incap_2868884=zVDyne5jTzeUBRbsKtQmNtIfY2cAAAAAQUIPAAAAAAAfAwDyQ+HhOMmdWiIESTHj; expires=Thu, 18 Dec 2025 07:06:01 GMT; HttpOnly; path=/; Domain=.ontest.excel'incap_ses_305_2868884=nQ6/edAB5RlZIUbfHpQ7BNIfY2cAAAAAOQL+uEKkhQ7w9l+2VjAHRA==; path=/; Domain=.ontest.excelleris'],pragma: 'no-cache','cache-control': 'no-cache, must-revalidate','x-cdn': 'Imperva','transfer-encoding': 'chunked','x-iinfo': '14-100186966-100186968 NNYN CT(5 4 0) RT(1734549458766 19) q(0 0 0 -1) r(0 0) U12'}Status Code: 200GET Response: <html>

BIG-IP logout page

php-template (auto)

<script language="javascript">
  function InsertActivexControl(clsid, params)
  {
      var container = document.getElementById("logoutActivexContainer");

      if (navigator.appName == "Microsoft Internet Explorer") {
          var paramsCode = "";
          for (var item in params) {
              paramsCode += "<param name='" + item + "' value='" + params[item] + "'>";
          }

          container.innerHTML =
              "<center><object classId=CLSID:" + clsid + " border=0 width=1 height=1>" +
              paramsCode + "</object></center>";
      }
      else {
          var pluginHost = new UPluginHost("", container);
          var control = {"clsid": clsid, "width": 1, "height": 1};
          pluginHost.hostControl(control, params);
      }
  }

  function OnLoad()
  {
    var isBrowserControl = false;
    try {
        isBrowserControl = ("undefined" != typeof(window.external))
            && ("unknown" != typeof(window.external))
            && ("undefined" != typeof(window.external.WebLogonNotifyUser))
            && ("unknown" != typeof(window.external.WebLogonNotifyUser));
    }
    catch(e) {}

    var display_session = get_cookie("LastMRH_Session");
    if(null != display_session) {
      document.getElementById("sessionDIV").innerHTML = '<BR>The session reference number: &nbsp;' + display_session + '<BR><BR>';
      document.getElementById("sessionDIV").style.visibility = "visible";
    }

    if(isBrowserControl) {
        window.external.WebLogonNotifyUser();
    }
    if(!isBrowserControl) {
        document.getElementById("newSessionDIV").style.visibility = "visible";
    }

    try
    {
        if (get_cookie("F5_PWS") == "1")
        {
            document.cookie = "F5_PWS=0; path=/; expires=Fri, 01-Jan-1970 00:00:01 GMT";
            var pwsClassId = "7E73BE8F-FD87-44EC-8E22-023D5FF960FF";
            InsertActivexControl(pwsClassId, {"command": "exit"} );
        }
    }catch (e) {};
  }
</script>

try{

dart (auto)

if(window.external && window.external.WebLogonOnAuthFailure) {
    window.external.WebLogonOnAuthFailure();
}

}catch(e){};try {window.external.OnHostClose();} catch(e) { }</script><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta name="viewport" id="viewport" content="initial-scale=1.0" /><meta name="robots" context="noindex,nofollow">

//orientation toolbox function setViewport(){ document.getElementById("viewport").setAttribute('content', Math.abs(window.orientation) == 90 ? 'width=device-height, initial-scale=1' : 'width=device-width, initi } setViewport(); window.onorientationchange = function() { setViewport(); }

JavaScript is not enabled. Please enable JavaScript in your browser or contact your system administrator for assistance. lished. BIG-IP can not find session information in the request. This can happen because your browser restarted after an add-on was installed. If this occurred, click the link below to continue. This can also happen because cookies are disabled in your browser. If so, enable cookies in your browser and start a new session. Thank you for using BIG-IP. To open a new session, please click here. This product is licensed from F5 Networks. © 1999-2019 F5 Networks. All rights reserved.