【问题标题】:Sub-request response stops the initial request in Kohana 3.2?子请求响应停止 Kohana 3.2 中的初始请求?
【发布时间】:2015-09-27 19:48:28
【问题描述】:

关注: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";
}

在我的控制器函数 action_getsettings() 中。

我正在使用 Request::factory() 而不是手动 curl 并且一切正常,但问题是 $request 的响应没有在 $response 中存储 - 它只是直接输出并退出控制器(它不去 json_decode 和 if 语句)

也尝试了$response = $request->execute()->body();,但它仍然像我一样输出return $response;

为什么会这样?

【问题讨论】:

  • 您将此代码放在哪里?在控制器内部,这会触发我的错误。 ErrorException [致命错误]:调用未定义的方法 Request_Client_Internal::options()

标签: curl request kohana kohana-3.2


【解决方案1】:
  1. 您将此代码放在哪里?在控制器内部,这会触发我的错误。: ErrorException [致命错误]:调用未定义的方法 Request_Client_Internal::options()。
  2. 您是在调用内部 uri 还是外部 uri?内部工作对我来说非常好。

`

$uri = 'controller/action';
$request = Request::factory($uri);
$request->execute();

【讨论】:

  • 我正在提出外部请求。 API 请求。在控制器内部是的,options() 没有错误,工作正常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 2011-02-18
  • 1970-01-01
相关资源
最近更新 更多