我正在处理一个nusoap客户端调用,对于一个web服务,我使用的是nusoap.php最后一个库。
当我制作XML结构时,我使用的是:
$string =<<<XML<?xml version='1.0'?><cliente>
<nombre>$posts['nombre']</nombre>
<apellido>$posts['apellido']</apellido>
<calle>$posts['direccion']</calle>
<altura>$posts['altura']</altura>
<pisodto>$posts['pisodto']</pisodto>
<localidad>$posts['localidad']</localidad>
<provincia>$posts['provincia']</provincia>
<partido>$posts['partido']</partido>
<telefono>$posts['telefono']</telefono>
<celular>$posts['celular']</celular>
<email>$posts['email']</email>
</cliente>
XML;
但出于某种原因,WAMP不喜欢它,我总是收到这样的错误:
分析错误:语法错误,意外的'<lt;'(T_SL)在G:''wamp''www''bsmart''PHPtoXML2''enviarxml.php中的第98行
这是的完整代码
date_default_timezone_set('America/Argentina/Buenos_Aires');
require_once 'assets/clases/nusoap/nusoap.php';
$wsdl = "http://ws.maxirest.com/wsclientes/wscli06896.php?WSDL";
$cliente = new nusoap_client($wsdl);
$produccion = false; //Cambiar a verdadero por producction
$endpoint = $wsdl;
//print_r($_POST);
$posts = $_POST;
if ($produccion == false) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
$posts['altura'] =
$posts['email'] =
"PRUEBA";
}
$string =<<<XML<?xml version='1.0'?><cliente>
<nombre>$posts['nombre']</nombre>
<apellido>$posts['apellido']</apellido>
<calle>$posts['direccion']</calle>
<altura>$posts['altura']</altura>
<pisodto>$posts['pisodto']</pisodto>
<localidad>$posts['localidad']</localidad>
<provincia>$posts['provincia']</provincia>
<partido>$posts['partido']</partido>
<telefono>$posts['telefono']</telefono>
<celular>$posts['celular']</celular>
<email>$posts['email']</email>
</cliente>
XML;
$param = array('cXml' => $string, 'clave' => "123ClubMilaMREST5");
$client = new nusoap_client($wsdl);//Ruta donde se encuentra nuestro servicio para consumirlo
$resultado = $client->call('AltaSolicitud',$param);
//Codigo para debugear y ver la respuesta y posibles errores, comentar cuando se comprueba que está correcto el servicio y la llamada
$err = $client->getError();
if ($err) {
echo '<p><b>Constructor error: ' . $err . '</b></p>';
}
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo htmlspecialchars($client->response, ENT_QUOTES) . '</b></p>';
echo '<p><b>Debug: <br>';
echo htmlspecialchars($client->debug_str, ENT_QUOTES) .'</b></p>';
//Comentar hasta aquí
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode.")</p>";
echo "String: ".$client->faultstring;
}
else
{
var_dump ($resultado);
}
我想可能会少一个图书馆,但我不确定,任何帮助都将不胜感激,提前谢谢。
您需要在XML后面有一个换行符。
$string = <<<XML
^
line break mandatory, it marks the end of the "XML" mark (heredoc identifier).
有关重要的详细信息,请参阅PHP Heredoc字符串语法。
此外,字符串中的数组字符串键不会被引用。
完整示例:
$string = <<<XML
<?xml version='1.0'?><cliente>
<nombre>$posts[nombre]</nombre>
<apellido>$posts[apellido]</apellido>
<calle>$posts[direccion]</calle>
<altura>$posts[altura]</altura>
<pisodto>$posts[pisodto]</pisodto>
<localidad>$posts[localidad]</localidad>
<provincia>$posts[provincia]</provincia>
<partido>$posts[partido]</partido>
<telefono>$posts[telefono]</telefono>
<celular>$posts[celular]</celular>
<email>$posts[email]</email>
</cliente>
XML;