Closed jgrancher closed 7 years ago
Depends on what you mean. If you're trying to issue a POST
from the client, you could use .evaluate()
and XMLHttpRequest
(or use/.inject()
your tool of choice) to issue the request.
Could you provide more information about your use case?
@rosshinkley I've got two options:
form-data
parameters. This will also lead me to the "Page B" results.
Screenshot from Postman:
The second option would be quicker as I would skip the first page. I wondered is such a thing is possible with Nightmare. Something like:
const url = 'http://url-page-b.com';
const headers = { method: 'POST', 'cache-control': 'no-cache' };
const data = { id_stuff: '160', ... };
nightmare.goto(url, headers, data);
Hope that's clear enough! Thanks :)
I have a similar problem, have to write a bunch of tests to cover some functionality of a project we're working on and being able to do this would make the login step much faster, particularly given that we want to run every test in as isolated a fashion as possible.
method post is not part of "header" the original question has it correctly. I suppose if one could figure out actions maybe some serious hackery could be done there.
really needs to be a new verb method in Nightmare class itself.
Change or create new methods for .GET .POST .DELETE .PUT .SEARCH implement accordingly.
It seems like this is a core electron problem.
https://discuss.atom.io/t/add-http-post-method-to-electron-webview/29702
It comes back to the metaphor of the software. It's a browser and it is impossible from a URL input to perform anything but a http GET from the URL address line. .goto
is the same as typing into the browser a location, which is only ever going to be a .GET method.
So running arbitrary js fun is the only way.
You might be able to send a POST manually through AJAX/fetch etc then replace the HTML of the page in the webview with the HTML returned by your manual POST. You can achieve this using .executeJavaScript() and/or Electron's IPC.
Is there an decent example for doing this?
You could also fire type events to fill in each of the input fields and then click the submit button.
I agree with @kmacpher67
It's a browser and it is impossible from a URL input to perform anything but a http GET from the URL address line.
Would be really convenient we could do a client.post(url, headers, data) instead of client.evaluate(...) I guess we can make a nightmarejs action for that, any examples?
Thanks for this library, it's really awesome. I've had to deal with a new use case recently, and I didn't see any example related.
So my question is: Can I use Nightmare, somehow, to post some data through the HTTP body? Example of what I'd like, using the request library: