SilverStripe:如何向另一个网站发出 HTTP 请求?
SilverStripe: How do I make HTTP Request to another website?
我正在尝试在控制器方法内向另一个网站发出 HTTP 请求。我搜索了解决方案,但找不到任何有效的示例。
这是我的代码:
$r = new HttpRequest('http://community.bba.org/home', HttpRequest::METH_GET);
$r->addQueryData(array('SessionID' => $arrGetParams['SessionID']));
try {
$r->send();
} catch (HttpException $ex) {}
我收到以下错误:
Fatal error: Class 'HttpRequest' not found in C:\wamp\www\abb\mysite\code\form\ALoginForm.php on line 215
我怎样才能让这个 HTTP 请求正常工作?
我在 Windows 7 机器上的 WAMP 上使用 SilverStripe。
http://php.net/manual/en/http.install.php
This » PECL extension is not bundled with PHP.
此问题与SilverStripe本身无关。您需要安装该模块,或使用 curl(wampserver 与它捆绑在一起)。
How to enable curl in Wamp server
有http://docs.silverstripe.org/en/3.1/developer_guides/integration/restfulservice/但我不推荐
向外部站点或资源发出请求的内置方法是使用 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();
如果您想使用 PHP 的 HTTPRequest
,您必须安装 http 扩展 (http://php.net/manual/en/http.install.php)
我正在尝试在控制器方法内向另一个网站发出 HTTP 请求。我搜索了解决方案,但找不到任何有效的示例。
这是我的代码:
$r = new HttpRequest('http://community.bba.org/home', HttpRequest::METH_GET);
$r->addQueryData(array('SessionID' => $arrGetParams['SessionID']));
try {
$r->send();
} catch (HttpException $ex) {}
我收到以下错误:
Fatal error: Class 'HttpRequest' not found in C:\wamp\www\abb\mysite\code\form\ALoginForm.php on line 215
我怎样才能让这个 HTTP 请求正常工作?
我在 Windows 7 机器上的 WAMP 上使用 SilverStripe。
http://php.net/manual/en/http.install.php
This » PECL extension is not bundled with PHP.
此问题与SilverStripe本身无关。您需要安装该模块,或使用 curl(wampserver 与它捆绑在一起)。 How to enable curl in Wamp server
有http://docs.silverstripe.org/en/3.1/developer_guides/integration/restfulservice/但我不推荐
向外部站点或资源发出请求的内置方法是使用 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();
如果您想使用 PHP 的 HTTPRequest
,您必须安装 http 扩展 (http://php.net/manual/en/http.install.php)