Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

~veHagah !

Fatal error: Uncaught exception 'Exception' with message '

Recommended Posts

Quando informo os dados do clientes, dá a mensagem abaixo. Alguem sabe como solucionar?

 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/zzzzzzzz/html/xxxxx/carrega_.php:32 Stack trace: #0 /var/www/zzzzzz/html/xxxxxx/teste_.php(32): SimpleXMLElement->__construct('') #1 {main} thrown in /var/www/zzzzzzzz/html/xxxxx/teste_.php on line 32

 

<?php

$_POST['codigo'] = (int) $_POST['codigo'];
$_POST['digito'] = (int) $_POST['digito'];

if ((is_int($_POST['codigo']) && $_POST['codigo'] != 0) && is_int($_POST['digito'])) {
       $fp = fsockopen("000.000.00.000", 00, $errno, $errstr, 30);
       if (!$fp) {
               echo "$errstr ($errno)<br />\n";
       } else {
               $out = "POST /ws.asmx/Consulta HTTP/1.1\r\n";
               $out .= "Host: 000.000.00.000\r\n";
               $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
               $out .= "Content-Length: xxxlen\r\n\r\n";
               $tudo .= "Parametros=<sdtconweb xmlns=\"\">\r\n    <CodCliente>" . $_POST['codigo'] . "</CodCliente>\r\n    <DigCliente>" . $_POST['digito'] . "</DigCliente>\r\n</sdtconweb> \r\n";

               $out .= $tudo;

               $out = str_replace('xxxlen',strlen($tudo)-3,$out);

               fwrite($fp, $out);
               $xml = '';
               while (!feof($fp)) {
                       $xml .= fgets($fp, 128);
               }
               fclose($fp);
       }

       $xml = substr($xml,strpos($xml,'<string xmlns="http://tempuri.org/xxxxxxxxxx/ws">')+strlen('<string xmlns="http://tempuri.org/xxxxxxxxxx/ws">'));
       $xml = substr($xml,0,strpos($xml,'</string>'));
       $xml = html_entity_decode($xml);
       $xml = new SimpleXMLElement($xml);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>xxxxx</title>
<script type="application/javascript">
function popup(end,npop,larg,alt) {
       window.open(end, npop, 'status=yes,height='+alt+',width='+larg+',top='+(window.screen.height/2-alt/2)+',left='+(window.screen.width/2-larg/2));
}
function validar() {
       return true;
       if (!isNaN(document.getElementById('codigo').value) || document.getElementById('codigo').value == '') {
               alert('Digite um código válido!');
               document.getElementById('codigo').focus();
               return false;
       }
       if (isNaN(document.getElementById('digito').value) || document.getElementById('digito').value == '') {
               alert('Digite um digito válido!');
               document.getElementById('digito').focus();
               return false;
       }
}
</script>
<style type="text/css">
body{
       background: url(imagens/fundo.jpg) center top no-repeat;
       margin-top: 100px;
}
* {

Compartilhar este post


Link para o post
Compartilhar em outros sites

A variável $xml não contém uma marcação XML válida.

 

Ola Evandro.. Agradeço a resposta.

 

Acontece que o codigo funcionava perfeitamente ate semana passada.

Realizei a troca de servidor, e então começou a dar este problema..

 

Na teoria, não entendo como possa ser "XML inválido", pois a unica alteracao que teve, foi do IP.

 

Versao do PHP e o codigo continuam o mesmo...

 

Teria mais alguma dica?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Antes da linha 32, adicione a seguinte linha:

 

die('<pre>' . print_r($xml, 1) . '</pre>');

 

e poste o conteúdo da saída.

Compartilhar este post


Link para o post
Compartilhar em outros sites

eh so ler a mensagem, uma ida ao google tradutor pode ser, String could not be parsed as XML, a string nao pode ser interpretada como xml....e pelo codigo, eh o q o evandro disse: a tring nao tem marcacao nenhuma de xml...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Quando mudou de servidor mudou de Windows para Linux (ou vice-versa)?

 

Se for o caso, substitua os \n\r por PHP_EOL e verifique o comportamento.

http://php.net/manual/pt_BR/reserved.constants.php

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.