我正在尝试使用PHP访问SOAP API,为此,我需要使用PHP cURL在计算机上下载一个WSDL描述文件的副本。
这是我正在使用的代码:
<?php
$ch = curl_init();
$credit = ('some_username'.':'.'some_password');
curl_setopt($ch, CURLOPT_URL, 'https://somevalidaddress/file.asmx?WSDL');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $credit);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$path = 'C:'Wamp'www'mmx'test2.xml';
file_put_contents($path, $data);
?>
文件test2.xml包含,每次在第345行(总共684行)包含一个随机字符(例如ø、@或VT等)。此外,文件的最后一个字符是剥离的。
我在谷歌上搜索了这个东西,我读到了"一比一"错误和缓冲区溢出的消息,但我仍然没有解决我的问题的方法。
知道吗?谢谢
如何使用这个:
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
));
$data = file_get_contents('https://somevalidaddress/file.asmx?WSDL', false, $context);