Axios returning binary data instead of XML
Hey all, I asked this question earlier and got further with my research into what its doing. however I am having a issue with Axios in particular in sending out a dynamicly generated XML response.
The XML request I am generating is essentially this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://projectorpsa.com/DataContracts/Shared/Common/"
xmlns:pws="http://projectorpsa.com/PwsProjectorServices/" xmlns:req="http://projectorpsa.com/DataContracts/Requests/" xmlns:sch="http://projectorpsa.com/DataContracts/Shared/Scheduling/">
<soapenv:Header />
<soapenv:Body>
<pws:PwsGetProject>
<pws:serviceRequest>
<req:SessionTicket>BZZ=</req:SessionTicket>
<sch:Mode>R</sch:Mode>
<sch:ProjectIdentities>
<com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210115-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-08</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-09</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103101-10</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103103</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103110-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103110-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2103110-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-08</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-09</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210378-10</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>210966</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-01</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-02</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-03</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-04</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-05</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-06</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>211245-07</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>2201146</com:ProjectCode></com:PwsProjectRef>
<com:PwsProjectRef><com:ProjectCode>ARCH - 3708608015</com:ProjectCode></com:PwsProjectRef>
</sch:ProjectIdentities>
</pws:serviceRequest>
</pws:PwsGetProject>
</soapenv:Body>
</soapenv:Envelope>
which I generate through a for Loop:
//xmlCode Example: XMLCode: `<com:PwsProjectRef><com:ProjectCode>${e.ProjectCode[0]}</com:ProjectCode></com:PwsProjectRef>`
for(let i = 0; i < idArray.length; i++){
if (i === 0){
genXML = idArray[i].XMLCode + "n";
}
if (i === idArray.length - 1){
genXML = genXML + " " + idArray[i].XMLCode;
}
else{
genXML = genXML + " " + idArray[i].XMLCode + "n"
}
}
which Axios is generating as:
data: '<?xml version="1.0" encoding="UTF-8"?>n' +
' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://projectorpsa.com/DataContracts/Shared/Common/" n' +
' xmlns:pws="http://projectorpsa.com/PwsProjectorServices/" xmlns:req="http://projectorpsa.com/DataContracts/Requests/" xmlns:sch="http://projectorpsa.com/DataContracts/Shared/Scheduling/">n' +
' <soapenv:Header />n' +
' <soapenv:Body>n' +
' <pws:PwsGetProject>n' +
' <pws:serviceRequest>n' +
' <req:SessionTicket>BZ</req:SessionTicket>n' +
' <sch:Mode>R</sch:Mode>n' +
' <sch:ProjectIdentities>n' +
' <com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-02</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-03</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-04</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-05</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-06</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210115-07</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-02</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-03</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-04</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-05</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-06</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-07</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-08</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-09</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103101-10</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103103</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103110-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103110-02</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2103110-03</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-02</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-03</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-04</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-05</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-06</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-07</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-08</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-09</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210378-10</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>210966</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-02</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-03</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-04</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-05</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-06</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>211245-07</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2201146</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2201147</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220340-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2205110</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220967-01</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220967-02</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220967-03</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220967-04</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220967-05</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220967-06</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>220991</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>2210125</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>677800-10593</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>677900-10594</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707607943</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707682075</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707736194</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3707756855</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708308023</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708308024</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708324520</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708387896</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708387898</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708398379</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708437324</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708437327</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708437328</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708478136</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708510538</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708510540</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708567478</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708587301</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708608015</com:ProjectCode></com:PwsProjectRef>n' +
' '... 231 more characters
},
the issue i’m having is that Axios is returning what appears to be hex/binary data back from this call:
data: 'x1F�bx00x00x00x00x00x04x00��x07`x1CI�%&/m�{x7FJ�J��t�b�`x13$ؐ@x10������x1DiG#)�*��eVe]fx16@�흼��{���{���;�N'���?\fdx01l��J�ɞ!���x1F?~|x1F?"x1E7�N��yY���ݢ\6���>�����ݻ�t�/�fL�7U�x1AW��]�r7�7�~tD�?�f�G�_^5���˺��|ھʛU�lx14�x05��o�z�d�i��K/�x1BU�:�/�i�x00(}x1Ex00[���z�rx03{��
�I�l�l�6w
when I should be getting XML back. However, in that for loop, if I remove the else statement:
for(let i = 0; i < idArray.length; i++){
if (i === 0){
genXML = idArray[i].XMLCode + "n";
}
if (i === idArray.length - 1){
genXML = genXML + " " + idArray[i].XMLCode;
}
}
which generates:
data: '<?xml version="1.0" encoding="UTF-8"?>n' +
' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://projectorpsa.com/DataContracts/Shared/Common/" n' +
' xmlns:pws="http://projectorpsa.com/PwsProjectorServices/" xmlns:req="http://projectorpsa.com/DataContracts/Requests/" xmlns:sch="http://projectorpsa.com/DataContracts/Shared/Scheduling/">n' +
' <soapenv:Header />n' +
' <soapenv:Body>n' +
' <pws:PwsGetProject>n' +
' <pws:serviceRequest>n' +
' <req:SessionTicket>B</req:SessionTicket>n' +
' <sch:Mode>R</sch:Mode>n' +
' <sch:ProjectIdentities>n' +
' <com:PwsProjectRef><com:ProjectCode>201268</com:ProjectCode></com:PwsProjectRef>n' +
' <com:PwsProjectRef><com:ProjectCode>ARCH - 3708608015</com:ProjectCode></com:PwsProjectRef>n' +
' </sch:ProjectIdentities>n' +
' </pws:serviceRequest>n' +
' </pws:PwsGetProject>n' +
' </soapenv:Body>n' +
' </soapenv:Envelope>n'
},
it works perfectly, generating the XML I need back. So I’m presuming my issue is with how that else statement is being formulated. Even though it all appears to look good and well. I’m at a loss as to why axios is doing this. In the above post I mentioned that other libraries are working fine with this, but I can’t get Axios to do it. Hoping someone might have a idea!
Thank you for the help!