How does Puppeteer make an POST request?

there is currently an interface that needs to be requested using the POST method, and then the interface will return the HTML page, and we will save the HTML page as a PDF file.

const puppeteer = require("puppeteer");
(async() => {
    const browser = await puppeteer.launch({
        args: ["--no-sandbox", "--disable-setuid-sandbox"]
    });
    const page = await browser.newPage();
    await page.setRequestInterception(true);
    page.on("request", interceptedRequest => {
        var data = {
            url: "http://localhost/print",
            "method": "POST",
            "postData": "operatingAccountID=57207213d41ce5d90300007c"
        };
        interceptedRequest.continue(data);
        console.log(interceptedRequest.method(),"method")//GET
    });
    await page.goto("http://localhost/print");
    await page.screenshot({path: "example.png"});
    await page.pdf({path: "example.pdf", format: "A4"});
    await browser.close();
    
})();

the above code has made some changes with reference to issue and stackoverflow in github, but currently method cannot be set to POST.

Mar.03,2021

Why do I have to send a POST request in puppeteer?
find something to send POST request, then send the received html to puppeteer via setContent (html) for rendering, and save pdf

after that.
Menu