2015-07-26 2 views
2

мне нужно, чтобы получить расположение заголовка следующего запроса:PHP прибудет расположение заголовку после почтового запроса

This является то, что запрос выглядит как из инструмента хрома сети Дев, когда я исполню ее в хроме.

here - это запрос на переадресацию в хром-сетевом устройстве, на всякий случай, если это необходимо по какой-либо причине.

Я попытался следующие вещи:

это, кажется, только дайте мне пустой ответ:

<?php 
$url = $_GET["url"]; 
if (0 === preg_match('/form_build_id" value="form-([^"]*)"/', file_get_contents('http://anything2mp3.com/'), $matches)) exit("false"); 
$id = $matches[1]; 

$params = array('http' => array(
    'method' => 'POST', 
    'content' => array(
     'url' => $url, 
     'op' => "Convert", 
     'form_build_id' => "form-" . $id, 
     'form_id' => "videoconverter_convert_form" 
    ), 
    'max_redirects' => "0", 
    'header' => "Content-Type:application/x-www-form-urlencoded" 
)); 
stream_context_set_default($params); 
$headers = get_headers("http://anything2mp3.com/?q=&mobile_detect_caching_notmobile&mobile_detect_caching_nottablet", false, $ctx); 
echo implode("\n", $headers); 
?> 

я также попытался это:

<?php 
$url = $_GET["url"]; 
if (0 === preg_match('/form_build_id" value="form-([^"]*)"/', file_get_contents('http://anything2mp3.com/'), $matches)) exit("false"); 
$id = $matches[1]; 

$params = array('http' => array(
    'method' => 'POST', 
    'content' => array(
     'url' => $url, 
     'op' => "Convert", 
     'form_build_id' => "form-" . $id, 
     'form_id' => "videoconverter_convert_form" 
    ), 
    'max_redirects' => "0", 
    'header' => "Content-Type:application/x-www-form-urlencoded" 
)); 
$ctx = stream_context_create($params); 
$file = fopen("http://anything2mp3.com/?q=&mobile_detect_caching_notmobile&mobile_detect_caching_nottablet", 'rb', false, $ctx); 
$headers = $http_response_header; 
echo implode("\n", $headers); 
?> 

последний дает мне следующий результат:

HTTP/1.1 200 OK 
Date: Sun, 26 Jul 2015 18:20:20 GMT 
Content-Type: text/html; charset=utf-8 
Connection: close 
Set-Cookie: __cfduid=db7807d30a61600d31a18cc1a725150811437934820; expires=Mon, 25-Jul-16 18:20:20 GMT; path=/; domain=.anything2mp3.com; HttpOnly 
Vary: Accept-Encoding 
X-Cookie-Domain: .anything2mp3.com 
Expires: Tue, 24 Jan 1984 08:00:00 GMT 
Last-Modified: Sun, 26 Jul 2015 18:20:20 GMT 
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0 
ETag: W/"1437934820" 
Content-Language: en 
X-Device: normal 
X-GeoIP-Country-Code: US 
X-GeoIP-Country-Name: United States 
X-Speed-Cache-Key: /?q=&amp;mobile_detect_caching_notmobile&amp;mobile_detect_caching_nottablet 
X-NoCache: Method 
X-This-Proto: http 
X-Server-Name: anything2mp3.com 
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Server: cloudflare-nginx 
CF-RAY: 20c21e3333eb23a8-IAD 

, как вы можете видеть, нет заголовка местоположения.

Отметьте, что я уже видел похожие записи (например, вопрос 6532753, я не мог связать его, потому что я уже на моем лимите 2 ссылок), но они, похоже, не работают для меня.

Как получить заголовок местоположения из запроса, как отмечено в исходном скриншоте? Что мне не хватает?

редактировать: Я перепутался довольно трудно при копировании моего кода, жаль что

+1

Обычно я использую завиток, чтобы сделать что-то подобное, отключил последующее перенаправление и выполнил его вручную. – frz3993

ответ

1

В конце концов я получил его на работу, используя завиток как @ frz3993 предложил (и после отправки в пустом заголовке «Cookies», то Didn сервера «т, кажется, как без этого)

вот код, который я использую сейчас:

<?php 
$url = $_GET["url"]; 
if (0 === preg_match('/form_build_id" value="form-([^"]*)"/', file_get_contents('http://anything2mp3.com/'), $matches)) exit("false"); 
$longid = $matches[1]; 

$ch = curl_init("http://anything2mp3.com/?q=&mobile_detect_caching_notmobile&mobile_detect_caching_nottablet"); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
     'url' => $url, 
     'op' => "Convert", 
     'form_build_id' => "form-" . $longid, 
     'form_id' => "videoconverter_convert_form" 
    ))); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type:application/x-www-form-urlencoded", 
    "Cookie:" 
    )); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
$data = curl_exec($ch); 
if (0 === preg_match('/Location: (.*id=(\d+))/', $data, $matches)) exit("false"); 
$redirect = $matches[1]; 
$id = $matches[2]; 
echo $redirect; 
echo " - "; 
echo $longid; 
die(); 
?> 

отмечают, что даже то второе предложение от моего OP дал мне заголовки, он не давал мне место который теперь скручивается. (не спрашивайте меня, почему: p)

Смежные вопросы