Custom headers
Send your own specified headers, including cookies
You can pass custom headers by using the headers parameter and specifying the headers in a dictionary, where each key represents the header name and its corresponding value represents the header value
To use your cookies in a request you can pass an array of dictionaries, where each dictionary represents a single cookie with a "key" and a "value" key-value pair
Below are code examples using 2 custom cookies, as well as 2 headers, all of which you can customize:
curl -X POST -u username:password -H 'Content-Type: application/json' -d '{"target": "universal", "url": "http://httpbin.dev/headers", "geo": "United States", "headless": "html", "cookies": [{"key": "my_cookie", "value": "delicious"}, {"key": "second_cookie", "value": "delisheshner"}], "headers": {"Accept-Language": "en-US", "My-Header": "whatever you can imagine"}}' https://scraper-api.smartproxy.com/v2/scrape
import requests
payload = {
'target': 'universal',
'url': 'http://httpbin.dev/headers',
'geo': 'United States',
'headless': 'html',
'cookies': [{'key': 'my_cookie', 'value': 'delicious'}, {'key': 'another_cookie', 'value': 'delisheshner'}],
'headers': {'Accept-Language': 'en-US', 'My-Header': 'whatever you can imagine'}
}
response = requests.request(
'POST',
'https://scraper-api.smartproxy.com/v2/scrape',
auth=('username', 'password'),
json=payload,
)
print(response.text)
<?php
$payload = array(
'target' => 'universal',
'url' => 'http://httpbin.dev/headers',
'headless' => 'html',
'cookies' => array(array('key' => 'my_cookie', 'value' => 'delicious'), array('key' => 'second_cookie', 'value' => 'delisheshner')),
'headers' => array('Accept-Language' => 'en-US', 'My-Header' => 'whatever you can imagine')
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
Updated 30 days ago