优化 http 客户端
This commit is contained in:
parent
30e7829d21
commit
167ea743a0
@ -217,9 +217,8 @@ class Http
|
|||||||
*/
|
*/
|
||||||
public function get(string $url)
|
public function get(string $url)
|
||||||
{
|
{
|
||||||
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, array_merge($this->header, $this->query, $this->timeout, $this->options)));
|
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, $this->merge()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request post
|
* Request post
|
||||||
*
|
*
|
||||||
@ -229,9 +228,7 @@ class Http
|
|||||||
*/
|
*/
|
||||||
public function post(string $url)
|
public function post(string $url)
|
||||||
{
|
{
|
||||||
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, array_merge(
|
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, $this->merge()));
|
||||||
$this->header, $this->body, $this->formParams, $this->json, $this->timeout, $this->multipart,$this->options
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,9 +240,7 @@ class Http
|
|||||||
*/
|
*/
|
||||||
public function put(string $url)
|
public function put(string $url)
|
||||||
{
|
{
|
||||||
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, array_merge(
|
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, $this->merge()));
|
||||||
$this->header, $this->body, $this->formParams, $this->json, $this->timeout, $this->options
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -257,9 +252,21 @@ class Http
|
|||||||
*/
|
*/
|
||||||
public function delete(string $url)
|
public function delete(string $url)
|
||||||
{
|
{
|
||||||
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, array_merge(
|
return new Response($this->getClient()->{$this->asyncMethod(__FUNCTION__)}($url, $this->merge()));
|
||||||
$this->header, $this->query, $this->timeout, $this->options
|
}
|
||||||
)));
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* request params merge
|
||||||
|
*
|
||||||
|
* @time 2020年05月22日
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function merge()
|
||||||
|
{
|
||||||
|
return array_merge($this->header, $this->query, $this->timeout,
|
||||||
|
$this->options, $this->body, $this->auth, $this->multipart, $this->formParams
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,17 @@ class Response implements \ArrayAccess
|
|||||||
return $this->response->getBody();
|
return $this->response->getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应内容
|
||||||
|
*
|
||||||
|
* @time 2020年05月22日
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
public function contents()
|
||||||
|
{
|
||||||
|
return $this->body()->getContents();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2020年05月21日
|
* @time 2020年05月21日
|
||||||
@ -41,7 +52,7 @@ class Response implements \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public function json():array
|
public function json():array
|
||||||
{
|
{
|
||||||
return \json_decode($this->response->getBody()->getContents(), true);
|
return \json_decode($this->contents(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user