The following code that I have made in node works perfectly, what it does is bring me a pdf report from JasperReports Server, however, I would like to try to achieve this but without the use of Node, I have done the following but without any success, if someone can Help me with this I would really appreciate it.
Node:
app.post('/form-submit', async function (req, res) {
try {
const url = "http://localhost:8080/jasperserver/rest_v2/reports/reports/R011.pdf"
var params = {
FF:"1234"
}
const file = await axios.get(url, {
params: params,
responseType: "stream",
auth: {
username: "JASPER",
password: "JASPER"
}
})
res.writeHead(200, { "Content-Type": "application/pdf"})
file.data.pipe(res)
} catch (error) {
console.log(error)
}
});
Javascript
const prueba = async() => {
try {
const respuesta = await axios.get("http://localhost:8080/jasperserver/rest_v2/reports/reports/R011.pdf", {
params: {
FF:"1234"
},
headers: {
auth: {
username: "JASPER",
password: "JASPER"
}
},
responseType: "stream",
})
} catch (error) {
}
}
prueba()
Html:
<body>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/index.js"></script>
</body>