FabricioG
FabricioG

Reputation: 3320

Submit a form directly to request url

In puppeteer I directly submit forms by filling out the data needed then clicking the submit button. I'm wondering how could I submit a form directly to an api like the web page does. In example on this page when I submit the form it does a network request post to

https://www.example.com/api/v3/user?timestamp=1592947755672

Request Method: POST Then the Request Payload is a json object.

{firstName: "John",
lastName: "Travis"}

How can I pass my object to the url so that I could by pass filling out the form?

Upvotes: 1

Views: 149

Answers (1)

theDavidBarton
theDavidBarton

Reputation: 8851

It is something to do outside of puppeteer, but you can solve it with Node.

I.) If you prefer to solve it without a new dependency but with longer lines of callbacks you can do it with Node's "http" module http.request(options\[, callback\]).

II.) If you don't mind having a new dependency in your project then the npm package request was used for a long time as a simplified HTP client. It is deprecated as of February 11th 2020 so I'd suggest to use node-fetch (0 dependencies) or axios (1 dependency).

Request collects alternative libraries in this GitHub issue.

Upvotes: 1

Related Questions