File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,18 @@ protected function preparePayload($data)
250250 $ this ->setOpt (CURLOPT_POSTFIELDS , $ data );
251251 }
252252
253+ /**
254+ * Set the json payload informations to the postfield curl option.
255+ *
256+ * @param array $data The data to be sent.
257+ * @return void
258+ */
259+ protected function prepareJsonPayload (array $ data )
260+ {
261+ $ this ->setOpt (CURLOPT_POST , true );
262+ $ this ->setOpt (CURLOPT_POSTFIELDS , json_encode ($ data ));
263+ }
264+
253265 /**
254266 * Set auth options for the current request.
255267 *
@@ -307,12 +319,17 @@ public function get($url, $data = array())
307319 *
308320 * @param string $url The url to make the post request
309321 * @param array $data Post data to pass to the url
322+ * @param boolean $asJson Whether the data should be passed as json or not. {@insce 2.2.1}
310323 * @return self
311324 */
312- public function post ($ url , $ data = array ())
325+ public function post ($ url , $ data = array (), $ asJson = false )
313326 {
314327 $ this ->setOpt (CURLOPT_URL , $ url );
315- $ this ->preparePayload ($ data );
328+ if ($ asJson ) {
329+ $ this ->prepareJsonPayload ($ data );
330+ } else {
331+ $ this ->preparePayload ($ data );
332+ }
316333 $ this ->exec ();
317334 return $ this ;
318335 }
You can’t perform that action at this time.
0 commit comments