i would like to replace file_get_contents with curl (sipgate voip account) , but every tryout does not work.
Version mit file_get_contents:
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s@sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s@sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$context = stream_context_create(
array('http' => array(
'method' => "POST",
'header' => sprintf("Content-Type: text/xml\r\nAuthorization: Basic %s)", $auth),
'content' => $request
))
);
file_get_contents("https://api.sipgate.net/RPC2", false, $context);
Latest Tryouts with curl
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s@sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s@sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$context = stream_context_create(
array('http' => array(
'method' => "POST",
'header' => sprintf("Content-Type: text/xml\r\nAuthorization: Basic %s)", $auth),
'content' => $request
))
);
$url = 'https://api.sipgate.net/RPC2';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $context);
curl_exec($curl);
curl_close($curl);
AND
$requestParameter = array(
'RemoteUri' => sprintf('sip:%s@sipgate.de', $remoteUri),
'LocalUri' => sprintf('sip:%s@sipgate.de', $localUri),
'TOS' => 'voice'
);
$auth = base64_encode(sprintf('%s:%s', $username, $password));
$request = xmlrpc_encode_request("samurai.SessionInitiate", $requestParameter);
$url = 'https://api.sipgate.net/RPC2';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $auth);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_exec($curl);
curl_close($curl);
Has someone an idea for me? Thx, spf