1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Request.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\UpdateSystem;
4
5use Bitrix\Main\SystemException;
6use Bitrix\Main\Web\HttpClient;
7use Bitrix\Main\Web\HttpHeaders;
8use Bitrix\Main\Web\Uri;
9
11{
12 private string $method = 'POST';
13 private ?array $body = null;
14 private Uri $url;
15 private HttpClient $httpClient;
16
17 public function __construct()
18 {
19 $this->httpClient = new HttpClient();
20 $this->httpClient->setVersion('1.0');
21 }
22
23 public function setHeaders(HttpHeaders $headers): void
24 {
25 $this->httpClient->setHeaders($headers->toArray());
26 }
27
28 public function setUrl(Uri $url): void
29 {
30 $this->url = $url;
31 }
32
33 public function setMethod(string $method): void
34 {
35 $this->method = $method;
36 }
37
38 public function setProxy(array $proxyData): void
39 {
40 if (
41 isset($proxyData['host'])
42 && !empty($proxyData['host'])
43 && isset($proxyData['port'])
44 && !empty($proxyData['port'])
45 ) {
46 $this->httpClient->setProxy(
47 $proxyData['host'],
48 $proxyData['port'],
49 $proxyData['user'] ?? null,
50 $proxyData['password'] ?? null,
51 );
52 }
53 }
54
55 public function setBody(array $body): void
56 {
57 $this->body = $body;
58 }
59
64 public function send(): string
65 {
66 $this->url->addParams($this->body);
67 $isSuccess = $this->httpClient->query(
68 $this->method,
69 $this->url->getLocator(),
70 $this->body
71 );
72
73 if ($isSuccess)
74 {
75 return $this->httpClient->getResult();
76 }
77 else
78 {
79 if ($this->httpClient->getStatus() === 0 && empty($this->httpClient->getError()))
80 {
81 throw new \Exception('Invalid response from host: '.$this->url->getHost().' [RS01]', 400);
82 }
83 else
84 {
85 throw new SystemException(implode('\r\n', $this->httpClient->getError()).' [RS02]');
86 }
87 }
88 }
89}
setProxy(array $proxyData)
Определения Request.php:38
setMethod(string $method)
Определения Request.php:33
setUrl(Uri $url)
Определения Request.php:28
setBody(array $body)
Определения Request.php:55
setHeaders(HttpHeaders $headers)
Определения Request.php:23
Определения uri.php:17
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804