Skip to content

Commit

Permalink
Fixed code block in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitman666 committed Apr 3, 2014
1 parent ef8cd5f commit 0b85b9d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions README.md
Expand Up @@ -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);
Expand All @@ -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.

Expand All @@ -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.

Expand Down

0 comments on commit 0b85b9d

Please sign in to comment.