jaa*_*cky 0 php xml curl soap laravel
我尝试使用 Laravel 将 XML 空缺职位发送到 Web 服务,但我正在努力弄清楚如何连接到 Web 服务、授权和发送所需的数据。
我尝试过使用curl,但我得到了
错误:“” - 代码:0
下面是我的代码
$result // IS MY XML file
$username = 'username'
$password = 'password'
$URL = 'http://xxxxxx.com;
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"xmlRequest=" . $result);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_exec($ch);
if(!curl_exec($ch)){
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
curl_close($ch);
}
Run Code Online (Sandbox Code Playgroud)
另一个有帮助的问题是 - 是否有另一种无需使用 Curl 即可将数据发送到 SOAP Web 服务的方法?
先感谢您
就在这里。看看这个SoapClient类:你可以像这样使用它:
$options = [
'trace' => true,
'cache_wsdl' => WSDL_CACHE_NONE
];
$credentials = [
'username' => 'username'
'password' => 'password'
];
$header = new SoapHeader($NAMESPACE, 'AuthentificationInfo', $credentials);
$client = new SoapClient($WSDL, $options); // null for non-wsdl mode
$client->__setSoapHeaders($header);
$params = [
// Your parameters
];
$result = $client->GetResult($params);
// 'GetResult' being the name of the soap method
if (is_soap_fault($result)) {
error_log("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})");
}
Run Code Online (Sandbox Code Playgroud)
Laravel有这个库。我尝试了一下,然后最终编写了自己的包装器。