Skip to content

Commit 0ea7886

Browse files
authored
Merge pull request #145 from nly/master
* 解决 ?avinfo= 的问题,理论上 ?a=&b= 和 ?a&b 是一样的,但是七牛并不兼容 ?avinfo= 的格式
2 parents a549217 + 061359f commit 0ea7886

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/Client/Http/Client.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,17 @@ public function goGet($url = '', $query = null, $timeout = 30000, $headers = [])
322322
}
323323
$this->setHeaders($headers);
324324

325-
$sendGetReq = $this->getObject(Http::class, [$this, 'GET', $this->urlData['path'], $query, $timeout]);
325+
//支持直接在url之后带参数形式的GET请求
326+
$q = '';
327+
if (!empty($this->urlData['query'])) {
328+
$q = ltrim($this->urlData['query'], '?');
329+
}
330+
331+
if (!empty($query)) {
332+
$q .= empty($q) ? '' : '&' . http_build_query($query) ;
333+
}
334+
335+
$sendGetReq = $this->getObject(Http::class, [$this, 'GET', $this->urlData['path'], $q, $timeout]);
326336

327337
return $sendGetReq;
328338
}
@@ -427,12 +437,16 @@ public function goSingleGet($url = '', $query = [], $timeout = 30000, $headers =
427437
$this->setHeaders($headers);
428438

429439
//支持直接在url之后带参数形式的GET请求
440+
$q = '';
430441
if (!empty($this->urlData['query'])) {
431-
parse_str(trim($this->urlData['query'], '?'), $data);
432-
$query = array_merge($data, $query);
442+
$q = ltrim($this->urlData['query'], '?');
443+
}
444+
445+
if (!empty($query)) {
446+
$q .= empty($q) ? '' : '&' . http_build_query($query) ;
433447
}
434448

435-
return yield $this->getObject(Http::class, [$this, 'GET', $this->urlData['path'], $query, $timeout]);
449+
return yield $this->getObject(Http::class, [$this, 'GET', $this->urlData['path'], $q, $timeout]);
436450
}
437451

438452
/**
@@ -668,13 +682,13 @@ public static function parseUrl($url)
668682
* 发起异步GET请求
669683
*
670684
* @param string $path 待请求的URL Path
671-
* @param array $query 查询参数
685+
* @param string $query 查询参数
672686
* @param $callback
673687
*/
674-
public function get($path, $query, $callback)
688+
public function get($path, string $query, $callback)
675689
{
676690
if (!empty($query)) {
677-
$path = $path . "?" . http_build_query($query);
691+
$path = $path . '?' . $query;
678692
}
679693
$this->client->get($path, $callback);
680694
}

0 commit comments

Comments
 (0)