지정된 API 엔드포인트에 GET/POST 요청을 보냅니다.
이 코드들은 샘플이므로, 요청할 API의 사양에 맞게 헤더와 본문에 적절한 값을 설정하세요.
지정된 URL에 GET 요청 보내기
const url = "API URL";
// Send GET request
const response = await page.request.get(url);
// Check status code
if (response.status() !== 200) {
throw new Error("Error " + response.status());
}
// Parse JSON and output log
const data = await response.json();
console.log(data);
지정된 URL에 POST 요청 보내기
const url = "API URL";
// Send POST request
const response = await page.request.post(url, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
data: "key=value", // Form data
});
// Check status code
if (response.status() !== 200) {
throw new Error("Error " + response.status());
}
// Parse JSON and output log
const data = await response.json();
console.log(data);