Skip to content

Commit 3dc96b7

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 5255fda commit 3dc96b7

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
@@ -165,7 +165,12 @@ private function action ($action_path, $http_method, $put_post_parameters = null
165165
// Lets decide what type of action we are taking...
166166
switch ($http_method) {
167167
case "GET":
168-
// Nothing extra to do.
168+
// Set "POST" data - cURL will translate this into the appropriate
169+
// querystring so we don't have to worry about it.
170+
$action_postfields_string = http_build_query($put_post_parameters);
171+
curl_setopt($prox_ch, CURLOPT_POSTFIELDS, $action_postfields_string);
172+
unset($action_postfields_string);
173+
169174
break;
170175
case "PUT":
171176
curl_setopt($prox_ch, CURLOPT_CUSTOMREQUEST, "PUT");
@@ -323,21 +328,21 @@ public function get_version () {
323328
/*
324329
* object/array? get (string action_path)
325330
*/
326-
public function get ($action_path) {
327-
return $this->action($action_path, "GET");
331+
public function get ($action_path, $parameters = array()) {
332+
return $this->action($action_path, "GET", $parameters);
328333
}
329334

330335
/*
331336
* bool put (string action_path, array parameters)
332337
*/
333-
public function put ($action_path, $parameters) {
338+
public function put ($action_path, $parameters = array()) {
334339
return $this->action($action_path, "PUT", $parameters);
335340
}
336341

337342
/*
338343
* bool post (string action_path, array parameters)
339344
*/
340-
public function post ($action_path, $parameters) {
345+
public function post ($action_path, $parameters = array()) {
341346
return $this->action($action_path, "POST", $parameters);
342347
}
343348

0 commit comments

Comments
 (0)