3

当我向我的 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 ); 

以下是接受post的路线

Route::any('/api/requesthandler', 'TestController@requesthandler');

任何帮助表示赞赏。

4

4 回答 4

4

如果您使用以下命令,您可以在 curl 中跟踪最多 5 层的重定向:

curl_setopt($session, CURLOPT_FOLLOWLOCATION, true); 

然后,如果您 curl 重定向的页面,您的 curl 将从它重定向到的页面返回数据,而不是您当前看到的数据。

于 2014-01-24T20:55:05.463 回答
1

我在 Laravel 5.2 中遇到了这个问题。就我而言,这是因为TokenMismatchException. 将特定路由添加到 CSRF 验证异常列表为我解决了这个问题。

app/Http/Middleware/VerifyCsrfToken.php

protected $except = [
    'your route here'
];
于 2016-12-16T03:39:04.887 回答
0

重定向将您带到http://erm.gratuz.net.com/api/requesthandler但您的 cURL 调用将转到http://erm.gratuz.net.com/api/requesthandler/ - 我假设重定向是 Laravel 剥离尾部斜杠。

于 2014-01-24T20:30:07.933 回答
0

尝试在您的 laravel 项目文件中禁用 http_only:session.php

http_only => false,

于 2020-01-23T14:22:33.913 回答