/** * Send request to Bitrix (check o receive) * @param array $pPayload * @return array|bool */ protected static function sendRequest(array $pPayload) { $request = new CHTTP(); $request->http_timeout = self::CONNECTION_TIMEOUT; $request->setFollowRedirect(true); @$request->Post(self::getCheckerUrl(), $pPayload); if($request->status === 200 && $request->result) { return self::decodeResponse($request->result); } else { return false; } }
public static function sPost($url, $arPostData, $follow_redirect = false) //static post { $ob = new CHTTP(); $ob->setFollowRedirect($follow_redirect); return $ob->Post($url, $arPostData); }
protected function queryOld($scope, $method = "GET", $data = null, $skipRefreshAuth = false) { if ($this->engineSettings['AUTH']) { $http = new \CHTTP(); $http->setAdditionalHeaders(array('Authorization' => 'OAuth ' . $this->engineSettings['AUTH']['access_token'])); $http->setFollowRedirect(false); switch ($method) { case 'GET': $result = $http->get($scope); break; case 'POST': $result = $http->post($scope, $data); break; case 'PUT': $result = $http->httpQuery($method, $scope, $http->prepareData($data)); break; case 'DELETE': break; } if ($http->status == 401 && !$skipRefreshAuth) { if ($this->checkAuthExpired(false)) { $this->queryOld($scope, $method, $data, true); } } $http->result = Text\Encoding::convertEncoding($http->result, 'utf-8', LANG_CHARSET); return $http; } }
function gdGetRss($rss_url, $cache_time = 0) { /** @global CMain $APPLICATION */ global $APPLICATION; $cache = new CPHPCache(); if (!$cache->StartDataCache($cache_time, 'c' . $rss_url, "gdrss")) { $v = $cache->GetVars(); return $v['oRss']; } $oRssFeeds = new gdRssFeeds(); $ob = new CHTTP(); $ob->http_timeout = 10; $ob->setFollowRedirect(true); $ob->HTTPQuery("GET", $rss_url); $res = $ob->result; if (!$res) { $cache->EndDataCache(array("oRss" => false)); return false; } if (preg_match("/<" . "\\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\\?" . ">/i", $res, $matches)) { $charset = trim($matches[1]); $res = $APPLICATION->ConvertCharset($res, $charset, SITE_CHARSET); } $xml = new CDataXML(); $xml->LoadString($res); $oNode = $xml->SelectNodes("/rss/channel/title"); if (!$oNode) { $cache->EndDataCache(array("oRss" => false)); return false; } $oRssFeeds->title = $oNode->content; if (trim($oRssFeeds->title) == '') { if ($oSubNode = $oNode->elementsByName("cdata-section")) { $oRssFeeds->title = $oSubNode[0]->content; } } if ($oNode = $xml->SelectNodes("/rss/channel/link")) { $oRssFeeds->link = $oNode->content; } if ($oNode = $xml->SelectNodes("/rss/channel/description")) { $oRssFeeds->description = $oNode->content; } if (trim($oRssFeeds->description) == '') { if ($oNode && ($oSubNode = $oNode->elementsByName("cdata-section"))) { $oRssFeeds->description = $oSubNode[0]->content; } } if ($oNode = $xml->SelectNodes("/rss/channel/pubDate")) { $oRssFeeds->pubDate = $oNode->content; } elseif ($oNode = $xml->SelectNodes("/rss/channel/lastBuildDate")) { $oRssFeeds->pubDate = $oNode->content; } if ($oNode = $xml->SelectNodes("/rss/channel")) { $oNodes = $oNode->elementsByName("item"); foreach ($oNodes as $oNode) { $item = array(); if ($oSubNode = $oNode->elementsByName("title")) { $item["TITLE"] = $oSubNode[0]->content; } if (trim($item["TITLE"]) == '' && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["TITLE"] = $oSubNode[0]->content; } } if ($oSubNode = $oNode->elementsByName("link")) { $item["LINK"] = $oSubNode[0]->content; } if ($oSubNode = $oNode->elementsByName("pubDate")) { $item["PUBDATE"] = $oSubNode[0]->content; } if ($oSubNode = $oNode->elementsByName("description")) { $item["DESCRIPTION"] = $oSubNode[0]->content; } if (trim($item["DESCRIPTION"]) == '' && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["DESCRIPTION"] = $oSubNode[0]->content; } } if ($oSubNode = $oNode->elementsByName("author")) { $item["AUTHOR"] = $oSubNode[0]->content; } if (trim($item["AUTHOR"]) == '' && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["AUTHOR"] = $oSubNode[0]->content; } } $oRssFeeds->items[] = $item; } } $cache->EndDataCache(array("oRss" => $oRssFeeds)); return $oRssFeeds; }
$this->IncludeComponentTemplate('sync'); } break; case 'test': if (!check_bitrix_sessid()) { return; } $sp_server = $_REQUEST['sp_server']; $sp_user = $_REQUEST['sp_user']; $sp_pass = $_REQUEST['sp_pass']; $arResult['SERVER'] = 0; $arResult['AUTH'] = 0; if ($sp_server && $sp_server != 'http://' && ($URL = CHTTP::ParseURL($sp_server))) { if ($URL['host'] && $URL['scheme'] == 'http') { $ob = new CHTTP(); $ob->setFollowRedirect(false); if ($sp_user) { $ob->SetAuthBasic($sp_user, $sp_pass); } if ($ob->Get($sp_server) !== false) { if ($ob->status == 200 || $ob->status == 302 || $ob->status == 401) { $arResult['SERVER'] = 1; if ($ob->status != 401) { $arResult['AUTH'] = 1; } } } } } $this->IncludeComponentTemplate('form_server_test'); break;