diff --git a/README.md b/README.md index 6c917b8..28fb3ae 100644 --- a/README.md +++ b/README.md @@ -10,25 +10,30 @@ Following is the PHP cURL wrapper class which I use to make GET and POST request Simple GET request ================================= -`require("CurlWrapper_static.php"); +```PHP +require("CurlWrapper_static.php"); $googleHTML = CurlWrapper::SendRequest('https://www.google.com'); -echo $googleHTML;` +echo $googleHTML; +``` If you're a firm non-static lover here's a "normal" class simple GET request usage: -`require("CurlWrapper_nonStatic.php"); +```PHP +require("CurlWrapper_nonStatic.php"); $curl = new CurlWrapper(); $googleHTML = $curl->SendRequest('https://www.google.com'); -echo $googleHTML;` +echo $googleHTML; +``` JSON POST request ================= Here's an example of sending a JSON POST request to imaginitive URL 'http://service.com/getData.json' with some data array: -`require("CurlWrapper_static.php"); +```PHP +require("CurlWrapper_static.php"); $cookieSettingUrl = 'http://service.com/'; $cookie = CurlWrapper::SendRequest($cookieSettingUrl); @@ -46,7 +51,8 @@ $headers = array('Accept: application/json','Content-Type: application/json'); $resultsHTML = CurlWrapper::SendRequest($jsonUrl, $cookieSettingUrl, "POST", $postData, $headers); $resultsJson = json_decode($resultsHTML); -var_dump($resultsJson);` +var_dump($resultsJson); +``` Important to note is that you have to add proper $headers array, and that you json_encode your data array as shown when POSTing to a service which expects JSON data. @@ -55,9 +61,11 @@ Cookies The reason why I first used these two lines: -`$cookieSettingUrl = 'http://service.com/'; +```PHP +$cookieSettingUrl = 'http://service.com/'; -$cookie = CurlWrapper::SendRequest($cookieSettingUrl);` +$cookie = CurlWrapper::SendRequest($cookieSettingUrl); +``` is to set any cookies (and you will find that some services do this) that may be needed to be sent along with the request to 'http://service.com/getData.json'. Cookies are set to 'curlCookies.txt' in the CurlWrapper_* class. You can change this to your liking, and you have to make sure that you set proper permissions for this file.