atk14 / url-fetcher
Class providing methods to make http requests
Installs: 38 537
Dependents: 6
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- atk14/string-buffer: >=1.2.2 <2.0
Requires (Dev)
- atk14/tester: *
This package is auto-updated.
Last update: 2024-11-24 15:30:31 UTC
README
UrlFetcher is a PHP class providing methods to make http requests
Basic usage
$fetcher = new UrlFetcher("http://www.example.com/content.dat");
if(!$fetcher->found()){
echo $fetcher->getErrorMessage();
exit(1);
}
$content = $fetcher->getContent();
$status_code = $fetcher->getStatusCode(); // e.g 200
$content_type = $fetcher->getContentType(); // e.g. "application/pdf"
$request_headers = $fetcher->getRequestHeaders();
$response_headers = $fetcher->getResponseHeaders();
HTTP basic authentication or non-standard port can be specified within the URL.
$fetcher = new UrlFetcher("https://username:password@www.example.com:444/private/content.dat");
if($fetcher->found()){
echo $fetcher->getContent();
}else{
echo $fetcher->getErrorMessage();
}
Make a POST requests
$fetcher = new UrlFetcher("https://www.example.com/api/en/articles/create_new/");
if($fetcher->post(["title" => "Sample article", "body" => "Lorem Ipsum..."])){
echo $fetcher->getContent();
}
Installation
Use the Composer to install the UrlFetcher.
cd path/to/your/project/
composer require atk14/url-fetcher
Licence
UrlFetcher is free software distributed under the terms of the MIT license