PHP HTTP请求 [英] PHP HTTP-Request
本文介绍了PHP HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我安装了运行php 5.2.13的MAMP Pro。当我尝试初始化HTTP-Request
I have MAMP Pro installed running php 5.2.13. When I try to initialize a HTTP-Request
$r = new HttpRequest('http://example.com/', HttpRequest::METH_GET);
它告诉我:
类'HttpRequest'未找到...。
"Class 'HttpRequest' not found in ...".
我需要做什么才能'安装(?)'它?
What do I need to do to 'install(?)' it?
推荐答案
MAMP 2.0和HTTP_Request2的当代答案:
Contemporary Answer for MAMP 2.0 and HTTP_Request2:
进入你的MAMP / bin / php / php5.3.6 / bin /并运行
Go into your MAMP/bin/php/php5.3.6/bin/ and run
./ pear install --alldeps HTTP_Request2
./pear install --alldeps HTTP_Request2
从PEAR存储库重新启动服务器并使用以下代码进行测试:
Restart your server and test with the following code, from the PEAR repository:
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
try {
$response = $request->send();
if (200 == $response->getStatus()) {
echo $response->getBody();
} else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
} catch (HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>
不要忘记require_once语句!
Don't forget the require_once statement!
这篇关于PHP HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文