在带有curl的PHP中第三方URL重定向后,如何获得响应?
function curlRequest($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
return $result;
}
答案 0 :(得分:0)
curl_test_redirect.php
<?php
function curlRequest($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
return $result;
}
echo curlRequest('http://localhost//myWork/testPHP/curl_first_hit.php');
?>
curl_first_hit.php
<?php
echo 'hello in first hit';
header('Location: http://localhost//myWork/testPHP/curl_second_hit.php');
?>
curl_second_hit.php
<?php
echo 'hello in second hit';
?>