-1

What is the c# alternative of the java code below?

await page.evaluate(() => {
  return fetch('url', {method: 'POST', body: 'test' });
});

I need to send a post request using PuppeteerSharp. There are several ways but it seems it is the easiest one, But I did not find any alternative for the fetch method.

for the evaluate method I found this method await page.EvaluateFunctionAsync for C#, but How can I use fetch inside?

Inside Man
  • 4,194
  • 12
  • 59
  • 119

1 Answers1

2

In Puppeteer, the function that we provide to page.evaluate is executed in context of the page and so it has to be a JavaScript function.

Likewise, in the equivalent functions in puppeteer-sharp e.g. page.EvaluateFunctionAsync, the first argument is a string which is nothing but a JavaScript function. You should be able to use the fetch as it is, something like:

await page.EvaluateFunctionAsync(@"() => {
  return fetch('url', {method: 'POST', body: 'test' });
}");
yeniv
  • 1,589
  • 11
  • 25