Custom POST Data, Referer and Cookie


Custom POST Data:

You can customize the request which is sent to the target page for the screenshot. You can include any POST Data, like you were sending a form. This pages shows hot to use the feature from Browshot.

For example, let us say you would like to take a screenshot of your Browshot dashboard at "https://browshot.com/dashboard". In order to access this page, you must be logged in. To login, you can fill out the form at "https://browshot.com/login" with your username and password, and you will be redirected to your dashboard. Browshot support redirections, so this is fine.

Let us say your username is foo and password is bar. You need to pass this value to post_data:

username=foo&password=bar

If you use any of the Browshot libraries, you do not need to worry about encoding data:

$browshot->create_screenshot(url => 'https://browshot.com/login', post_data => 'username=foo&password=bar'); # Full API, Perl
$browshot->simple(url => 'https://browshot.com/login', post_data => 'username=foo&password=bar'); # Simple API, Perl
client.screenshot_create('https://browshot.com/login', { 'post_data' => 'username=foo&password=bar' }); # Full API, Ruby
client.simple('https://browshot.com/login', { 'post_data' => 'username=foo&password=bar' }); # Simple API, Ruby

However, if you prefer to use the command line to get a screenshot, you need to take care of encoding the post_data value correctly: & becomes %26, = becomes %3d, etc.:

wget "https://api.browshot.com/api/v1/simple?url=https://browshot.com/login&post_data=username%3dfoo%26password%3dbar&key=my_api_key" -O /tmp/dashboard.png

Custom Referer:

Similarly, you can define a custom Referer header. Some websites display different content if the user comes from a search engine, or redirect users to the home page is they do not come from the same site.

Like for the post_data parameter, you need to encode the Referer URL if you use the command line.

If you want to simulate a request by a user coming from a Google search for "test screenshot", you can use the Refer http://www.google.com/?q=test+screeenshot. Using wget, it looks like this:

wget "https://api.browshot.com/api/v1/simple?url=http://website.com/&referer=http://www.google.com/%3Fq%3Dtest%2Bscreeenshot&key=my_api_key" -O /tmp/search.png

Custom Cookie:

You can use a custom cookie string, for example to reuse an existing session. The cookie is set for the URL of the target site.

The cookie string can contain several key=value pairs.

Like for the post_data and referer parameters, you need to encode the cookie string if you use the command line.


close

Sign up for a free account