Skip to content

Commit 7a5067d

Browse files
committed
修复get请求 传入data参数无效的BUG
1 parent 94788fd commit 7a5067d

File tree

109 files changed

+23
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+23
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions

example/cookie.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/HttpClient.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
class HttpClient
1212
{
13-
private $version = '2.0.1';
13+
private $version = '2.0.2';
1414

1515
/** 请求 **/
1616
public $request = [
@@ -30,14 +30,14 @@ class HttpClient
3030
/** 配置 **/
3131
public $options = [
3232
//超时
33-
'timeout' => 3,
33+
'timeout' => 3,
3434

3535
//代理ip池
36-
'proxyIps' => [],
36+
'proxyIps' => [],
3737

3838
//允许重定向及重定向次数
39-
'redirects' => false,
40-
'redirectMax' => 5,
39+
'redirects' => false,
40+
'redirectMax' => 5,
4141

4242
//保存cookie的文件路径
4343
'cookieJarFile' => '',
@@ -182,8 +182,20 @@ public function __construct($options = [])
182182
$this->options = array_merge($this->options, $options);
183183
}
184184

185-
public function get($url, $data = [], $headers = [])
185+
public function get($url, $data, $headers = [])
186186
{
187+
/** 拼接url中的get参数 **/
188+
if (!empty($data)) {
189+
if (is_string($data)) {
190+
parse_str($data,$data);
191+
}
192+
193+
if (strpos($url, '?') === false) {
194+
$url .= '?' . http_build_query($data);
195+
} else {
196+
$url .= '&' . http_build_query($data);
197+
}
198+
}
187199
return $this->request($url, 'GET', $data, $headers);
188200
}
189201

File renamed without changes.
File renamed without changes.
File renamed without changes.

example/get_1.php renamed to test/test.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@
1515
//'cookieJarFile' => 'D:\www\test\http-client\example\cookie.txt',
1616
];
1717
$http = new \Webguosai\HttpClient($options);
18-
$response = $http->get('http://www.baidu.com');
19-
if ($response->ok()) {
20-
dump($response->body);
21-
} else {
22-
dump($response->getErrorMsg());
23-
}
24-
25-
$url = 'http://test.com/test/http-client/example/test.php?a=1';
18+
19+
$url = 'http://test.com/test/http-client/test/server.php?a=1';
2620
//$url = 'http://127.0.0.1:10453/think';
2721
//$url = 'http://waophp.com/api/test';
2822
//$url = 'https://www.qq.com/';
@@ -42,7 +36,8 @@
4236
//纯字符串(\n)
4337
$headers3 = "Accept-Language: zh-CN,zh;q=0.9\nCache-Control: max-age=0\nConnection: keep-alive";
4438

45-
$response = $http->get($url, ['get'=>'111'], $headers);
39+
//$response = $http->get($url, ['get'=>'111'], $headers);
40+
$response = $http->get($url, 'get=111&get2=222', $headers);
4641

4742
//$response = $http->post($url, ['post'=>'111'], $headers);
4843
//$response = $http->post($url, '{"post":"222"}', $headers);
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)