Authentication 如何向需要身份验证的网站发送外部请求-Kohana 3.3

Authentication 如何向需要身份验证的网站发送外部请求-Kohana 3.3,authentication,login,request,external,kohana,Authentication,Login,Request,External,Kohana,我正在使用Kohana 3.3,并试图向我们公司内部的url发出外部请求。外部网站需要用户凭据。我如何向该网站提出外部请求?我计划使用一个请求登录,然后点击我想要的URL,但是我如何实现它呢?。下面是示例代码 Request::factory('http://example.com/user/login')->method('POST')->post('username', 'abc')->post('password', '123')->execute();

我正在使用Kohana 3.3,并试图向我们公司内部的url发出外部请求。外部网站需要用户凭据。我如何向该网站提出外部请求?我计划使用一个请求登录,然后点击我想要的URL,但是我如何实现它呢?。下面是示例代码

     Request::factory('http://example.com/user/login')->method('POST')->post('username', 'abc')->post('password', '123')->execute();
    $request = Request::$current;

   $request->factory('http://example.com/do/this')->method('POST')->post('param1', 'value')->post('param2', 'value2');
  $response = $request->execute();
上述代码在$request->factory处失败,表示它不是对象,无法调用factory方法


有谁能告诉我,我在Kohana 3.3中试图实现的正确方法是什么?

要发送外部请求,您应该使用request::factory创建一个请求,然后执行它。请注意,$request->execute返回响应对象

要发出2个验证受保护站点的请求,请使用:

// We create $request object
$request = Request::factory('http://example.com/user/login')
    ->method('POST')
    ->post(array(
        'username' => 'abc',
        'password' => '1111'
    ));

// We execute $request - getting 1st response
$response1 = $request->execute();

// We setting new URL to our $request object and new POST params
$request
    ->url('http://example.com/do/this')
    ->post(array(
        'param1' => '1',
        'param2' => '2'
    ));;

// Now we can execute it again
$response2 = $request->execute();
这样的想法是-您可以使用一个请求对象来处理不同的实际请求