• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

puppeteer에서 POST로 요청 날리기

25 Apr 2019

Reading time ~1 minute

puppeteer에서 POST로 요청 날리기

puppeteer에서 request를 POST로 요청 하기 위해서는 다음과 같은 설정을 해야 합니다.

await page.setRequestInterception(true);
// create a flag to only modify the initial request
let reformatFirstRequest = true;

page.on('request', interceptedRequest => {
  if (reformatFirstRequest) {
    console.log('first-request');
    reformatFirstRequest = false;
    interceptedRequest.continue({
      method: 'POST',
      postData: JSON.stringify(data),
      headers: { 'Content-Type': 'application/json' }
    });
  } else {
    interceptedRequest.continue();
  }
});

interceptedRequest 를 한번만 하지 않으면 이후 해당 request에 대한 404 오류가 떨어질 수 있다.

끗~

참고 자료

  • Send POST request to a page and take screenshot #669


pupeteerpost Share Tweet +1