Skip to content

Commit 765bfbe

Browse files
committed
Add support for parameters to GET requests
Addresses GitHub Issue #8 - Set parameters as CURLOPT_POSTFIELDS, which cURL will automatically translate into the URL query string. This lets us pass the ?params versus &params logic off to cURL, which makes the code easier to maintain. - Allow all parameters passed to be empty by making the argument optional on GET, POST, and PUT. This is mostly for consistency. Signed-off-by: Daniel Hunsaker <[email protected]>
1 parent 206ae1e commit 765bfbe

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pve2_api.class.php

100755100644
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ private function action ($action_path, $http_method, $put_post_parameters = null
176176
// Lets decide what type of action we are taking...
177177
switch ($http_method) {
178178
case "GET":
179-
// Nothing extra to do.
179+
// Set "POST" data - cURL will translate this into the appropriate
180+
// querystring so we don't have to worry about it.
181+
$action_postfields_string = http_build_query($put_post_parameters);
182+
curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $action_postfields_string);
183+
unset($action_postfields_string);
184+
180185
break;
181186
case "PUT":
182187
curl_setopt($prox_ch, CURLOPT_CUSTOMREQUEST, "PUT");
@@ -334,21 +339,21 @@ public function get_version () {
334339
/*
335340
* object/array? get (string action_path)
336341
*/
337-
public function get ($action_path) {
338-
return $this->action($action_path, "GET");
342+
public function get ($action_path, $parameters = array()) {
343+
return $this->action($action_path, "GET", $parameters);
339344
}
340345

341346
/*
342347
* bool put (string action_path, array parameters)
343348
*/
344-
public function put ($action_path, $parameters) {
349+
public function put ($action_path, $parameters = array()) {
345350
return $this->action($action_path, "PUT", $parameters);
346351
}
347352

348353
/*
349354
* bool post (string action_path, array parameters)
350355
*/
351-
public function post ($action_path, $parameters) {
356+
public function post ($action_path, $parameters = array()) {
352357
return $this->action($action_path, "POST", $parameters);
353358
}
354359

0 commit comments

Comments
 (0)