PHP HTTP 请求

发布于 2024-10-09 22:51:42 字数 249 浏览 7 评论 0原文

我安装了 MAMP Pro,运行 php 5.2.13。当我尝试初始化 HTTP 请求时,

$r = new HttpRequest('http://example.com/', HttpRequest::METH_GET);

它告诉我:

“在...中找不到‘HttpRequest’类”。

我需要做什么来“安装(?)”它?

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);

it tells me:

"Class 'HttpRequest' not found in ...".

What do I need to do to 'install(?)' it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

走过海棠暮 2024-10-16 22:51:42

您必须启用http扩展:

http://www.php.net/manual/en/http.setup.php" php.net/manual/en/http.setup.php

或者你可以尝试新的 HTTP_Request2:

sudo pear install --alldeps HTTP_Request2-alpha

然后:

$req = new HTTP_Request2('your.url');
$req->setMethod('POST');
$req->setHeader("content-type", $mimeType);
$req->setBody('');
$response = $req->send();

You must enable http extension:

http://www.php.net/manual/en/http.setup.php

Or you can try new HTTP_Request2:

sudo pear install --alldeps HTTP_Request2-alpha

And then:

$req = new HTTP_Request2('your.url');
$req->setMethod('POST');
$req->setHeader("content-type", $mimeType);
$req->setBody('');
$response = $req->send();
属性 2024-10-16 22:51:42

MAMP 2.0 和 HTTP_Request2 的当代答案:

进入 MAMP/bin/php/php5.3.6/bin/ 并运行

./pear install --alldeps HTTP_Request2

重新启动服务器并使用 PEAR 存储库中的以下代码进行测试:

<?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 语句!

Contemporary Answer for MAMP 2.0 and HTTP_Request2:

Go into your MAMP/bin/php/php5.3.6/bin/ and run

./pear install --alldeps HTTP_Request2

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();
}
?>

Don't forget the require_once statement!

不交电费瞎发啥光 2024-10-16 22:51:42

您需要启用扩展...

将以下内容添加到您的 php.ini

extension = php_http.dll

显然,有人问了很多:

http://php.bigresource.com/Track/php-33sNme7A/

You need to enable the extension ...

add the following to your php.ini

extension = php_http.dll

Apparently that was asked a lot:

http://php.bigresource.com/Track/php-33sNme7A/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文