[PHP] Enviar cabeceras http con la función file_get_contents (sin cURL)

noviembre 7, 2018

Aunque lo más común y recomendable es que utilicemos cURL para este tipo de peticiones, podemos enviar cabeceras http utilizando la función file_get_contents de PHP. Utilizaremos el siguiente código a modo de ejemplo: 1 2 3 4 5 6 7 8 9 10 11 12 $ops = [ "http" => [ "method" => "GET", "header" => "Content-Type: text/html; charset=utf-8\r\n" . "Content-Language: es\r\n" . "Content-Encoding: UTF-8\r\n" ] ];   $context = ...