I'm studying cURL
to continue my application , I reviewed my code and monitored the network Twitter and got the following HTTP Headers
:
curl "https://twitter.com/"
-H "accept-encoding: gzip, deflate, br"
-H "accept-language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4"
-H "upgrade-insecure-requests: 1"
-H "user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
-H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
-H "cache-control: max-age=0"
-H "authority: twitter.com"
-H "cookie: (RETIRADO POR SEGURANÇA!) --compressed
My code is very simple, but the question has arisen, is there a need to make the same calls?
Down my simpleton code:
$cookies = [];
$url_twitter = 'https://twitter.com';
$twitter_cookies = curl_init();
curl_setopt_array($twitter_cookies, [
CURLOPT_URL => $url_twitter,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_COOKIEJAR => ROOT . 'system' . SEPARATOR . 'cookies' . SEPARATOR . $TwitterUser . '.txt',
CURLOPT_HEADERFUNCTION => function($twitter_cookies, $header) use (&$cookies) {
if (stripos($header, 'Set-Cookie:') === 0) {
if (preg_match('/Set-Cookie:\s?(.*?);/i', $header, $matches)) {
$cookies[] = $matches[1];
}
}
return strlen($header);
}
]
);
As you can see, I did not implement half of HEADERS requests that Twitter showed by copying the cURL
quoted at the beginning of the topic.
I do not know if it adds automatically, I understand the basics of HTTPS
, but do I need to make these calls or is it automatically added?
"accept-encoding: gzip, deflate, br"
"accept-language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4"
"upgrade-insecure-requests: 1"
"user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
"accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
"cache-control: max-age=0"