function send($request) { $fullUrl = ($this->Port == 443 ? "https" : "http") . "://" . $this->Server . ":" . $this->Port . $this->Path; $uri = new \Bitrix\Main\Web\Uri($fullUrl); if ($uri->getHost() == '') { $this->ErrorString = '<b>Error:</b> CSOAPClient::send() : Wrong server parameters.'; return 0; } else { $this->Server = $uri->getHost(); $this->Port = $uri->getPort(); $this->Path = $uri->getPathQuery(); } if ($this->Timeout != 0) { $fp = fsockopen($this->Server, $this->Port, $this->errorNumber, $this->errorString, $this->Timeout); } else { $fp = fsockopen($this->Server, $this->Port, $this->errorNumber, $this->errorString); } if ($fp == 0) { $this->ErrorString = '<b>Error:</b> CSOAPClient::send() : Unable to open connection to ' . $this->Server . '.'; return 0; } $payload = $request->payload(); $authentification = ""; if ($this->login() != "") { $authentification = "Authorization: Basic " . base64_encode($this->login() . ":" . $this->password()) . "\r\n"; } $name = $request->name(); $namespace = $request->get_namespace(); if ($namespace[strlen($namespace) - 1] != "/") { $namespace .= "/"; } $HTTPRequest = "POST " . $this->Path . " HTTP/1.0\r\n" . "User-Agent: BITRIX SOAP Client\r\n" . "Host: " . $this->Server . "\r\n" . $authentification . "Content-Type: text/xml; charset=utf-8\r\n" . "SOAPAction: \"" . $namespace . $request->name() . "\"\r\n" . "Content-Length: " . (defined('BX_UTF') && BX_UTF == 1 && function_exists('mb_strlen') ? mb_strlen($payload, 'latin1') : strlen($payload)) . "\r\n\r\n" . $payload; $this->SOAPRawRequest = $HTTPRequest; if (!fwrite($fp, $HTTPRequest)) { $this->ErrorString = "<b>Error:</b> could not send the SOAP request. Could not write to the socket."; $response = 0; return $response; } $rawResponse = ""; // fetch the SOAP response while ($data = fread($fp, 32768)) { $rawResponse .= $data; } // close the socket fclose($fp); $this->SOAPRawResponse = $rawResponse; $response = new CSOAPResponse(); $response->decodeStream($request, $rawResponse); return $response; }
function ShowSOAPFault($errorString) { global $APPLICATION; $response = new CSOAPResponse('unknown_function_name', 'unknown_namespace_uri'); if (is_object($errorString) and (get_class($errorString) == "CSOAPFault" or get_class($errorString) == "csoapfault")) { $response->setValue($errorString); } else { $response->setValue(new CSOAPFault('Server Error', $errorString)); } $payload = $response->payload(); header("SOAPServer: BITRIX SOAP"); header("Content-Type: text/xml; charset=\"UTF-8\""); Header("Content-Length: " . (defined('BX_UTF') && BX_UTF == 1 && function_exists('mb_strlen') ? mb_strlen($payload, 'latin1') : strlen($payload))); $APPLICATION->RestartBuffer(); echo $payload; die; }
$req->additional_headers['SOAPAction'] = $arParams["PR_NAMESPACE"] . $arSoapMethod; $result = $req->Query("POST", $arUrl["host"], $arUrl["port"], $arUrl["path"], $request_body, $arUrl["proto"], "text/xml; charset=utf-8"); if (!$req->errstr) { if ($req->status == 401) { $arResult["RESULT"]['ERROR'] = GetMessage("AUTH_ERROR"); } else { preg_match("/^<soap:Envelope.*>/i", $req->result, $preg); if (empty($preg) || $req->status != "200") { $arResult["RESULT"]['ERROR'] = GetMessage("WRONG_RESPONSE"); } } } else { $arResult["RESULT"]['ERROR'] = $req->errstr; } if (!$arResult["RESULT"]['ERROR']) { $response = new CSOAPResponse(); $response->decodeStream($arSoapRequest, "\r\n\r\n" . $req->result); if ($response->Value["return"]) { $resFormHtml = base64_decode($response->Value["return"]); //removing BOM if (substr($resFormHtml, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $resFormHtml = substr($resFormHtml, 3); } if (!$isUTF) { $resFormHtml = $APPLICATION->ConvertCharset($resFormHtml, "UTF-8", SITE_CHARSET); } if ($arActionType == "ACTIVATION") { if (!strpos($resFormHtml, GetMessage("ERROR_RESP_MESSAGE"))) { CUserOptions::SetOption($this->__name, "ACTIVATION", "Y", false, $ID); $arResult["FORWARD_BUTTON"] = "FORWARD_TO_PAYROLL_FROM"; $arResult["FORWARD_BUTTON_URL"] = $APPLICATION->GetCurPage();