Parameters as Headers

Along with the “traditional” means of passing parameters, we also support passing parameters as headers. Passing parameters such as api_key, render, ultra_premium and instruction_set is very straightforward.

  • API REQUEST

Instead of including the parameters in the URL

<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&render=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);

you can just pass them as headers

<?php
$url = "https://api.scraperapi.com?url=https://httpbin.org/ip";
$ch = curl_init();

$headers = array(
    'x-sapi-render: true',
    'x-sapi-api_key: <YOUR_API_KEY>'
);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$response = curl_exec($ch);

curl_close($ch);

print_r($response);
?>

Please note that the 'x-sapi-' prefix is used on each header to avoid collisions with headers used by target sites. We support all standard parameters available with the API. The instruction_set parameter is specifically supported only through headers.

  • PROXY MODE

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://httpbin.org/ip");
curl_setopt($ch, CURLOPT_PROXY, "http://scraperapi:<YOUR_API_KEY>@proxy-server.scraperapi.com:8001");
$headers = array('x-sapi-render: true');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$response = curl_exec($ch);

curl_close($ch);

print_r($response);
?>

Note that credentials must still be passed to the proxy in the manner shown above, not as headers.

Last updated