PHP HTTP-Request

后端 未结 3 758
囚心锁ツ
囚心锁ツ 2020-12-03 23:07

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


        
3条回答
  •  半阙折子戏
    2020-12-03 23:49

    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:

    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!

提交回复
热议问题