Book Image

PhantomJS Cookbook

By : Rob Friesel
Book Image

PhantomJS Cookbook

By: Rob Friesel

Overview of this book

Table of Contents (15 chapters)
PhantomJS Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Generating a POST request from PhantomJS


This recipe expands further on the webpage.open method by demonstrating its additional parameters for specifying an HTTP method and data. The recipe's discussion will also reframe the open method by illustrating how to use it for interacting with RESTful interfaces.

Getting ready

To run this recipe, we need a script that will make an HTTP request with a method other than GET, and some knowledge of what the URL expects with respect to the HTTP verb and the payload data (if any).

The script in this recipe is available in the downloadable code repository as recipe03.js under chapter03. If we run the provided example script, we must change to the root directory for the book's sample code.

Lastly, the script in this recipe runs against the demo site that is included with the cookbook's sample code repository. To run that demo site, we must have Node.js installed. In a separate terminal, change to the phantomjs-sandbox directory (in the sample code's directory...