Skip to content

Commit 6ec4234

Browse files
committed
修复get请求传入data参数,导致请求出错的问题
1 parent f938847 commit 6ec4234

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/HttpClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public function get(string $url, $data = [], $headers = [])
207207
}
208208
}
209209

210+
$data = [];
211+
210212
return $this->request($url, 'GET', $data, $headers);
211213
}
212214

test/server.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@
6363

6464

6565

66-
67-
function getAllHeaders()
68-
{
69-
foreach ($_SERVER as $name => $value)
66+
if (!function_exists('getAllHeaders')) {
67+
function getAllHeaders()
7068
{
71-
if (substr($name, 0, 5) == 'HTTP_')
69+
foreach ($_SERVER as $name => $value)
7270
{
73-
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
71+
if (substr($name, 0, 5) == 'HTTP_')
72+
{
73+
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
74+
}
7475
}
76+
return $headers;
7577
}
76-
return $headers;
77-
}
78+
}

test/test.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//报告E_NOTICE之外的所有错误(可解决变量不存在导致的错误,如GET、POST数据)
77
error_reporting(E_ALL & ~E_NOTICE);
88

9+
910
$options = [
1011
'timeout' => 10,
1112
'redirects' => true,
@@ -18,7 +19,7 @@
1819
$http = new \Webguosai\HttpClient($options);
1920

2021
$url = 'http://test.com/test/http-client/test/server.php?a=1';
21-
$url = 'http://test.com/test/task/test/charset/bom/';
22+
//$url = 'http://test.com/test/task/test/charset/bom/';
2223
//$url = 'http://test.com/test/task/test/charset/gbk/';
2324
//$url = 'http://127.0.0.1:10453/think';
2425
//$url = 'http://waophp.com/api/test';

0 commit comments

Comments
 (0)