php - curl instead of file_get_contents with context -
i replace file_get_contents curl (sipgate voip account) , every tryout 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 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 idea me? thx, spf
the above named error on both versions
$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 )) ); $data = http_build_query($context); $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, $data); 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); $data = http_build_query($request); $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, $data); curl_exec($curl); curl_close($curl);
Comments
Post a Comment