Created
April 7, 2012 16:55
-
-
Save phpfour/2330376 to your computer and use it in GitHub Desktop.
Generic use of pecl_http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// GET | |
$req = new HttpRequest('http://www.example.com'); | |
$req->send(); | |
echo "Response code: " . $req->getResponseCode(), PHP_EOL; | |
echo "Response body: ", PHP_EOL, $req->getResponseBody(); | |
// POST / PUT | |
$req = new HttpRequest('http://www.example.com/post'); | |
$req->addPostFields($someData); | |
$req->setMethod(HttpRequest::METH_POST); // OR HttpRequest::METH_PUT | |
$req->send(); | |
echo "Response code: " . $req->getResponseCode(), PHP_EOL; | |
echo "Response body: ", PHP_EOL, $req->getResponseBody(); | |
// DELETE | |
$req = new HttpRequest('http://www.example.com/post/1'); | |
$req->setMethod(\HttpRequest::METH_DELETE); | |
$req->send(); | |
echo "Response code: " . $req->getResponseCode(), PHP_EOL; | |
echo "Response body: ", PHP_EOL, $req->getResponseBody(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment