Custom Headers

If you would like to use your own custom headers (user agents, cookies, etc.) when making a request to the website, simply set keep_headers=true and send the API the headers you want to use. The API will then use these headers when sending requests to the website.

Note: Only use this feature if you need to send custom headers to retrieve specific results from the website. Within the API we have a sophisticated header management system designed to increase success rates and performance on difficult sites. When you send your own custom headers you override our header system, which oftentimes lowers your success rates. Unless you absolutely need to send custom headers to get the data you need, we advise that you donโ€™t use this functionality.

If you need to get results for mobile devices, use the device_type parameter to set the user-agent header for your request, instead of setting your own.

  • API REQUEST

<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&keep_headers=true"; $headerArray =
array(
"Content-Type: application/json",
"X-MyHeader: 123"
); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
  • PROXY MODE

<?php
$headerArray = array(
  "Content-Type: application/json",
  "X-MyHeader: 123"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://httpbin.org/ip");
curl_setopt($ch, CURLOPT_PROXY, "http://scraperapi.keep_headers=true:APIKEY@proxy-server.scraperapi.com:8001");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
  • SDK Method

# remember to install the library: composer require scraperapi/sdk
<?php
  $client = new ScraperAPIClient("APIKEY");
  $result = $client->get("http://httpbin.org/ip", ["headers" => ["X-MyHeader" => "123"]])->raw_body;
  print($result);

Last updated