当我向我的 Laravel 路由发出 cURL 请求时,它不仅返回过程的内容,它实际上将我重定向到主页,返回此 HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="1;url=http://erm.gratuz.net.com/api/requesthandler" />
<title>Redirecting to http://erm.gratuz.net.com/api/requesthandler</title>
</head>
<body>
Redirecting to <a href="http://erm.gratuz.net.com/api/requesthandler">http://erm.gratuz.net.com/api/requesthandler</a>.
</body>
</html>
我的 cURL 请求如下:
$url = "http://erm.gratuz.net.com/api/requesthandler/";
$session = curl_init( $url );
curl_setopt( $session, CURLOPT_HEADER, 0 );
curl_setopt( $session, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $session, CURLOPT_POSTFIELDS,$fields );
$response = curl_exec( $session );
curl_close( $session );
下面也是接受邮寄的路线
Route::any('/api/requesthandler', 'TestController@requesthandler');
感谢任何帮助。
最佳答案
如果您使用:
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
然后,如果您 curl 重定向的页面,您的 curl 将从它重定向到的页面返回数据,而不是您当前看到的数据。
关于php - curl 到 Laravel 导致重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21340347/