12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace TencentCloud\Common\Http;
- use GuzzleHttp\Client;
- class HttpConnection
- {
- private $client;
- private $profile;
- function __construct($url, $profile)
- {
- $this->client = new Client(["base_uri" => $url]);
- $this->profile = $profile;
- }
- private function getOptions()
- {
- $options = ["allow_redirects" => false];
- $options["timeout"] = $this->profile->getHttpProfile()->getReqTimeout();
- $options["proxy"] = $this->profile->getHttpProfile()->getProxy();
- return $options;
- }
- public function getRequest($uri = '', $query = [], $headers = [])
- {
- $options = $this->getOptions();
- if ($query) {
- $options["query"] = $query;
- }
- if ($headers) {
- $options["headers"] = $headers;
- }
- return $this->client->get($uri, $options);
- }
- public function postRequest($uri = '', $headers = [], $body = '')
- {
- $options = $this->getOptions();
- if ($headers) {
- $options["headers"] = $headers;
- }
- if ($body) {
- $options["form_params"] = $body;
- }
- return $this->client->post($uri, $options);
- }
- public function postRequestRaw($uri = '', $headers = [], $body = '')
- {
- $options = $this->getOptions();
- if ($headers) {
- $options["headers"] = $headers;
- }
- if ($body) {
- $options["body"] = $body;
- }
- return $this->client->post($uri, $options);
- }
- }
|