- Модуль: webservice
- Путь к файлу: ~/bitrix/modules/webservice/classes/general/soap/soapclient.php
- Класс: CSOAPClient
- Вызов: CSOAPClient::send
function send( $request )
{
$fullUrl = ($this->Port == 443 ? "https" : "http")."://".$this->Server.":".$this->Port.$this->Path;
$uri = new BitrixMainWebUri($fullUrl);
if($uri->getHost() == '')
{
$this->ErrorString = 'Error: 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 = 'Error: 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() ) . "rn" ;
}
$name = $request->name();
$namespace = $request->get_namespace();
if ($namespace[mb_strlen($namespace) - 1] != "/")
$namespace .= "/";
$HTTPRequest = "POST " . $this->Path . " HTTP/1.0rn" .
"User-Agent: BITRIX SOAP Clientrn" .
"Host: " . $this->Server . "rn" .
$authentification .
"Content-Type: text/xml; charset=utf-8rn" .
"SOAPAction: "" . $namespace . $request->name() . ""rn" .
"Content-Length: " . (defined('BX_UTF') && BX_UTF == 1 && function_exists('mb_strlen')? mb_strlen($payload, 'latin1') : mb_strlen($payload)) . "rnrn" .
$payload;
$this->SOAPRawRequest = $HTTPRequest;
if ( !fwrite( $fp, $HTTPRequest /*, strlen( $HTTPRequest )*/ ) )
{
$this->ErrorString = "Error: 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;
}