1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
http.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Sale\Helpers\Rest;
4
5
use Bitrix\Main;
6
use Bitrix\Main\Web\HttpClient;
7
use Bitrix\Main\Web\Json;
8
use Bitrix\Sale;
9
14
class
Http
15
{
22
public
static
function
sendRequest
(
string
$url
,
array
$params
,
array
$options
= []):
Sale
\
Result
23
{
24
$result
=
new
Sale\Result
();
25
26
$httpClientOptions = [];
27
if
(array_key_exists(
'HTTP_CLIENT_OPTIONS'
,
$options
) && is_array(
$options
[
'HTTP_CLIENT_OPTIONS'
]))
28
{
29
$httpClientOptions =
$options
[
'HTTP_CLIENT_OPTIONS'
];
30
}
31
32
$httpClient =
new
HttpClient
($httpClientOptions);
33
34
$isJsonRequest = isset(
$options
[
'JSON_REQUEST'
]) &&
$options
[
'JSON_REQUEST'
] ===
true
;
35
36
if
($isJsonRequest)
37
{
38
$httpClient->setHeader(
'Content-Type'
,
'application/json'
);
39
}
40
41
$response
= $httpClient->post(
42
$url
,
43
$isJsonRequest ?
Json::encode
(
$params
) :
$params
44
);
45
if
(
$response
===
false
)
46
{
47
$errors
= $httpClient->getError();
48
foreach
(
$errors
as
$code
=>
$message
)
49
{
50
$result
->addError(
new
Main
\
Error
(
$message
,
$code
));
51
}
52
53
return
$result
;
54
}
55
56
$httpStatus = $httpClient->getStatus();
57
if
($httpStatus === 200)
58
{
59
try
60
{
61
$response
=
Json::decode
(
$response
);
62
$response
= array_change_key_case(
$response
, CASE_UPPER);
63
}
64
catch
(
Main
\
ArgumentException
$exception)
65
{
66
$response
= [];
67
$result
->addError(
68
new
Main
\
Error
(
'Response decoding error'
,
'RESPONSE_DECODING_ERROR'
)
69
);
70
}
71
72
$result
->setData(
$response
);
73
}
74
75
return
$result
;
76
}
77
}
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\Web\HttpClient
Определения
httpclient.php:24
Bitrix\Main\Web\Json\decode
static decode($data)
Определения
json.php:50
Bitrix\Main\Web\Json\encode
static encode($data, $options=null)
Определения
json.php:22
Bitrix\Sale\Helpers\Rest\Http\sendRequest
static sendRequest(string $url, array $params, array $options=[])
Определения
http.php:22
$options
$options
Определения
commerceml2.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$errors
$errors
Определения
iblock_catalog_edit.php:74
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
Bitrix\Main\Web\Http
Определения
clientexception.php:3
Bitrix\Main
Bitrix\Sale\Discount\Result
Определения
compatibleformat.php:2
Bitrix\Sale
$message
$message
Определения
payment.php:8
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$response
$response
Определения
result.php:21
$url
$url
Определения
iframe.php:7
bitrix
modules
sale
lib
helpers
rest
http.php
Создано системой
1.14.0