I use php function file_get_contents and one of params is http headers. I make them such like this:
if (strpos($key, 'HTTP_') === 0) {
$key = strtolower(strtr(substr($key, 5), '_', '-'));
$this->headers .= $key . ': ' . $value . '\r\n';
}
but here is a problem, I should send headers in double quotes like this:
"Connection: close\r\nContent-Length: $data_len\r\n"
Here is an example of how do I make request:
$opts = array(
'http' => array(
'method' => "GET",
'header' => $this->headers
)
);
$this->data = file_get_contents('http://phd.yandex.net/detect', false, stream_context_create($opts));
but it is fails. If I replace $this->headers in array with a custom string of http headers, everything works fine.
how to make it works right?
\r\n?\r\nin the first code section - could this be the problem? I suspect it will not parse but you never know...\r\nit is a typo