我目前有一个Laravel应用程序,它执行从一个路由到同一路由内的另一个路由的CURL请求。我的卷发看起来像这样:
//LOGGING THAT A CURL CALL IS ABOUT TO BE MADE
$url = env('APP_URL') . '/tests/add/results';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //return server error
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLINFO_HEADER_OUT, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $test_post_data);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
在发送帖子的路由中,我记录的第一件事是请求数据:
//LOGING THAT I RECEIVED THE CURL CALL in receiving function
我注意到,请求数据的日志记录的时间与超时时间完全相同,这意味着请求实际上是在初始调用10秒后发送的。
在我的日志中,我会看到类似这样的内容:
10:10:10 - LOGGING CURL CALL
10:10:20 - Recieving CURL call
如果我将超时时间更改为30,那么日志会在30秒后显示我收到了CURL调用。
有人知道为什么会发生这种情况吗?
来自CURL的响应总是返回为false
。
发布于 2019-10-05 00:21:27
为了使post请求起作用,我执行了以下操作:我不是通过CURL调用路由,而是直接向route函数发送post
$testController = new TestsController;
$test_data_request = new \Illuminate\Http\Request();
$test_data_request->setMethod('POST');
$test_data_request->request->add( $test_post_data );
$testId = $testController->addTestResults($test_data_request);
https://stackoverflow.com/questions/55383584
复制相似问题