浏览代码

Missed some chagnes that are needed to pass GET params.

Shane Mc Cormack 8 年之前
父节点
当前提交
de84caa616
共有 1 个文件被更改,包括 31 次插入0 次删除
  1. 31 0
      src/MyDNSHostAPI.php

+ 31 - 0
src/MyDNSHostAPI.php

@@ -802,6 +802,18 @@
 
 			try {
 				if ($method == 'GET') {
+					if (count($data) > 0) {
+						$url = parse_url($url);
+						if (isset($url['query'])) {
+							$query = [];
+							parse_str($url['query'], $query);
+							$url['query'] = http_build_query(array_merge($query, $data));
+						} else {
+							$url['query'] = http_build_query($data);
+						}
+						$url = $this->unparse_url($url);
+					}
+
 					$response = Requests::get($url, $headers, $options);
 				} else if ($method == 'POST') {
 					$response = Requests::post($url, $headers, json_encode(['data' => $data]), $options);
@@ -829,4 +841,23 @@
 			$this->lastResponse = $data;
 			return $data;
 		}
+
+		/**
+		 * Take an array from parse_url and turn it back into a URL.
+		 *
+		 * @param $parsed_url Array from parse_url.
+		 * @return String representing the URL.
+		 */
+		function unparse_url($parsed_url) {
+			$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
+			$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
+			$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
+			$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
+			$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
+			$pass = ($user || $pass) ? "$pass@" : '';
+			$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
+			$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
+			$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
+			return "$scheme$user$pass$host$port$path$query$fragment";
+		}
 	}