Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { chromium } = require('playwright');
- (async () => {
- // Launch a browser and create a page
- const browser = await chromium.launch();
- const page = await browser.newPage();
- // Define the API endpoint and request data
- const apiEndpoint = 'https://example.com/api/endpoint'; // Replace with your API URL
- const body = {
- key1: 'value1',
- key2: 'value2',
- };
- // Configure the POST request
- const headers = {
- 'Content-Type': 'application/json',
- };
- const requestOptions = {
- method: 'POST',
- headers,
- body: JSON.stringify(body),
- };
- // Make the POST request
- const response = await page.goto(apiEndpoint, requestOptions);
- // Check the response status
- if (response.status() >= 200 && response.status()<400) {
- const responseBody = await response.json();
- console.log('Response:', responseBody);
- } else {
- console.error('Failed to make the API request');
- }
- // Close the browser
- await browser.close();
- })().catch((error) => console.error(error));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement