I’m trying to use the Browserless PDF API
, and for this I wrote the following code:
app.get("/api/pdf", async (request, response) => {
try {
const { data } = await axios.post("http://localhost:3001/pdf", {
url: "https://www.google.com/",
})
response.setHeader("content-type", "application/pdf")
response.contentType("application/pdf")
response.send(Buffer.from(data, "binary"))
} catch (error) {
console.log(error.message)
}
})
in browser its look like this:
but if I fulfill the equal curl request
curl -X POST
http://localhost:3001/pdf
-H 'Cache-Control: no-cache'
-H 'Content-Type: application/json'
-d '{
"url": "https://google.com/"
}' --output 'file.pdf'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 49148 0 49114 100 34 38039 26 0:00:01 0:00:01 --:--:-- 38040
its look like this
what’s wrong with my code?