如下:https://kohanaframework.org/3.2/guide/kohana/requests
我有这样的代码:
$request = Request::factory($url);
$request
->client()
->options(array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_USERPWD => 'test' . ':' . 'token'
));
$response = $request->execute();
$response = json_decode($response);
if(is_array($response) && isset($response['product_feed_url']))
{
echo "Ok Access";
}else{
echo "No Access";
}
在my controller函数action_getsettings()中。
我使用的是Request::factory()而不是手动curl,它工作得很好,但问题是$ Request的响应没有存储在$response中-它只是直接输出并退出控制器(它不去json_decode和if语句)
也尝试了$response = $request->execute()->body();
,但它仍然只是输出,如果我做了return $response;
为什么会发生这种情况?
- 你把代码放在哪里?在控制器内部,这会触发一个错误。ErrorException[致命错误]:调用未定义的方法Request_Client_Internal::options().
- 您正在调用内部uri还是外部uri ?
$uri = 'controller/action';
$request = Request::factory($uri);
$request->execute();