@@ -192,8 +192,37 @@ $checkPageContent = new HttpService(
192
192
## GuzzleHttpService
193
193
194
194
Attempt connection to a given HTTP host or IP address and try to load a web page
195
- using [ Guzzle] ( http://guzzle3.readthedocs.org/en/latest/ ) . The check also
196
- supports checking response codes and page contents.
195
+ using [ Guzzle] ( http://docs.guzzlephp.org ) . The check also supports checking
196
+ response codes and page contents.
197
+
198
+ The constructor signature of the ` GuzzleHttpService ` is as follows:
199
+
200
+ ``` php
201
+ /**
202
+ * @param string|Psr\Http\Message\RequestInterface|GuzzleHttp\Message\RequestInterface $requestOrUrl
203
+ * The absolute url to check, or a fully-formed request instance.
204
+ * @param array $headers An array of headers used to create the request
205
+ * @param array $options An array of guzzle options to use when sending the request
206
+ * @param int $statusCode The response status code to check
207
+ * @param null $content The response content to check
208
+ * @param null|GuzzleHttp\ClientInterface $guzzle Instance of guzzle to use
209
+ * @param string $method The method of the request
210
+ * @param mixed $body The body of the request (used for POST, PUT and DELETE requests)
211
+ * @throws InvalidArgumentException
212
+ */
213
+ public function __construct(
214
+ $requestOrUrl,
215
+ array $headers = [],
216
+ array $options = [],
217
+ $statusCode = 200,
218
+ $content = null,
219
+ $guzzle = null,
220
+ $method = 'GET',
221
+ $body = null
222
+ )
223
+ ```
224
+
225
+ Examples:
197
226
198
227
``` php
199
228
<?php
@@ -229,6 +258,33 @@ $checkPageContent = new GuzzleHttpService(
229
258
);
230
259
```
231
260
261
+ You can send JSON data by either providing a ` Content-Type ` header that includes
262
+ a JSON content type, or creating a request instance with JSON content:
263
+
264
+ ``` php
265
+ // Send page content
266
+ $checkPageContent = new GuzzleHttpService(
267
+ 'api.example.com/ping',
268
+ ['Content-Type' => 'application/json'],
269
+ [],
270
+ 200,
271
+ null,
272
+ null,
273
+ 'POST',
274
+ ['ping' => microtime()]
275
+ );
276
+
277
+ // Assuming Guzzle 6:
278
+ use GuzzleHttp\Psr7\Request;
279
+ $request = new Request(
280
+ 'POST',
281
+ 'http://api.example.com/ping',
282
+ ['Content-Type' => 'application/json'],
283
+ json_encode(['ping' => microtime()])
284
+ );
285
+ $checkPageContent = new GuzzleHttpService($request);
286
+ ```
287
+
232
288
## Memcache
233
289
234
290
Attempt to connect to given Memcache server.
0 commit comments