Get a Free Trial

How to post to a form and screenshot the result?

To post to a form you must first get the URL of the form that is being posted. To do this get the form HTML by looking at the source of the web page, which may look something like this.

<form action="http://www.example.com/login.php" method="post">
   <div class="FormRow">
      <label>Username</label>
      <input type="text" name="username" value="">
   </div>
   <div class="FormRow">
      <label>Password</label>
      <input type="password" name="password" value="">
   </div>
   <input type="submit" class="submit" value="Login">
</form>

Once you have the URL of form you need to specify the name and values of each of the form inputs so the post won’t be rejected by the target website. An example of this is shown below.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

ImageOptions options = new ImageOptions();
options.AddPostParameter("username", "bob");
options.AddPostParameter("password", "pass");

grabzIt.URLToImage("http://www.example.com/login.php", options);
grabzIt.Save("http://www.mywebsite.com/handler.ashx");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

ImageOptions options = new ImageOptions();
options.AddPostParameter("username", "bob");
options.AddPostParameter("password", "pass");

grabzIt.URLToImage("http://www.example.com/login.php", options);
grabzIt.Save("http://www.mywebsite.com/handler");
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.5.2/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").AddPostVariable("username", "bob").AddPostVariable("password", "pass")
.ConvertURL("http://www.example.com/login.php").Create();
</script>

When specifying post data in node.js you must URL encode the name and value of each post variable.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

client.url_to_image("http://www.example.com/login.php", {"postData":"username=bob&password=pass"});
client.save("http://www.example.com/handler", function (error, id){
    if (error != null){
        throw error;
    }
}); 	
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->AddPostParameter("username", "bob");
$options->AddPostParameter("password", "pass");

$grabzIt->URLToImage("http://www.example.com/login.php", $options);
$grabzIt->Save("http://www.mywebsite.com/handler.pl");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItImageOptions();
$options->AddPostParameter("username", "bob");
$options->AddPostParameter("password", "pass");

$grabzIt->URLToImage("http://www.example.com/login.php", $options);
$grabzIt->Save("http://www.mywebsite.com/handler.php");
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzItImageOptions.GrabzItImageOptions()
options.AddPostParameter("username", "bob");
options.AddPostParameter("password", "pass");

grabzIt.URLToImage("http://www.example.com/login.php", options)
grabzIt.Save("http://www.mywebsite.com/handler.py")

Remember when making requests please ensure all parameter values are URL encoded. Note that each POST name and value will also have to be URL encoded first.

https://api.grabz.it/services/convert?key=Sign in to view your Application Key&post=username%3Dbob%26password%3Dpass&format=jpg&url=http%3A%2F%2Fwww.example.com%2Flogin.php
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.add_post_parameter("username", "bob");
options.add_post_parameter("password", "pass");

grabzIt.url_to_image("http://www.example.com/login.php", options)
grabzIt.save("http://www.mywebsite.com/handler/index")