SilverStripe:如何向其他网站发出HTTP请求?

use*_*290 3 php httprequest silverstripe

我试图在控制器方法内向另一个网站发出HTTP请求.我搜索了解决方案,但我找不到任何有用的例子.

这是我的代码:

$r = new HttpRequest('http://community.bba.org/home', HttpRequest::METH_GET);
$r->addQueryData(array('SessionID' => $arrGetParams['SessionID']));
try {
    $r->send();
} catch (HttpException $ex) {}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

致命错误:第215行的C:\ wamp\www\abb\mysite\code\form\ALoginForm.php中找不到类'HttpRequest'

如何才能使此HTTP请求正常工作?

我在Windows 7机器上使用WAMP上的SilverStripe.

Dan*_*sby 5

向外部站点或资源发出请求的内置方式是使用 RestfulService

文档在这里:http://docs.silverstripe.org/en/3.1/developer_guides/integration/restfulservice/

典型用法:

$service = new RestfulService('http://community.bba.org/home', 1200); //domain, cache duration
$service->setQueryString(array(
    'SessionID' => $arrGetParams['SessionID'],
));
$response = $service->request();
$body = $response->getBody();
Run Code Online (Sandbox Code Playgroud)

如果你想使用PHP,HTTPRequest你必须安装http扩展(http://php.net/manual/en/http.install.php)