title: How can I solve "XML error parsing SOAP payload on line 1: Invalid document end" in PHP Nusoap
body: <p>I am just new to PHP Nusoap and I tried to run my program and I am getting this kind of error when I <code>print_r($client)</code>. Here is the error :</p>
  
  <blockquote>
    <p>Error: XML error parsing SOAP payload on line 1: Invalid document end</p>
  </blockquote>
  
  <p>I find some related topics, articles and questions in google they are unanswered and if there are answered it doesn't help or solve my problem
  I also print my request and reponse details here it is :</p>
  
  <pre><code>**Request**
  
  POST /Nusoap/webservice_server.php HTTP/1.0
  Host: sampleserver:8544
  User-Agent: NuSOAP/0.9.5 (1.123)
  Content-Type: text/xml; charset=ISO-8859-1
  SOAPAction: "urn:Insertwsdl#InsertData"
  Content-Length: 616
  
  &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:Insert"&gt;&lt;SOAP-ENV:Body&gt;&lt;tns:InsertData xmlns:tns="urn:Insert"&gt;&lt;data/&gt;&lt;data1/&gt;&lt;data2/&gt;&lt;data3/&gt;&lt;data4/&gt;&lt;/tns:InsertData&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;
  
  Response
  
  HTTP/1.1 200 OK
  Date: Thu, 26 Nov 2015 06:17:25 GMT
  Server: Apache/2.2.14 (Unix) PHP/5.2.11
  X-Powered-By: PHP/5.4.44
  Expires: Thu, 19 Nov 1981 08:52:00 GMT
  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  Pragma: no-cache
  X-SOAP-Server: NuSOAP/0.9.5 (1.123)
  Set-Cookie: PHPSESSID=rftjeluijhnej49rvpu94rs6f0; path=/
  Content-Length: 411
  Connection: close
  Content-Type: text/xml; charset=ISO-8859-1
  
  Data : Filename of of data
  Data1 : Sender of the data
  Data2 : Receiver of the data
  Data : Filename1 of the data
  Data1 : Sender1 of the data
  Data2 : Receiver1 of the data
  Da
  </code></pre>
  
  <p>for my code :</p>
  
  <p><strong>webservice_server.php</strong></p>
  
  <pre><code>&lt;?php 
  require_once('lib/nusoap.php');
  
  $server = new soap_server();
  
  $server-&gt;configureWSDL('Database Data Insertion', 'urn:Insert');
  //$server-&gt;soap_defencoding = 'utf-8';
  $server-&gt;register('InsertData',
      array(
          'data' =&gt; 'xsd:data',       
          'data1' =&gt; 'xsd:data1',
          'data2'  =&gt; 'xsd:data2',
          'data3'  =&gt; 'xsd:data3',
          'data4' =&gt; 'xsd:data4',
      ),
      array(
          'return' =&gt; 'xsd:string'        
      ),
      'urn:Insert',
      'urn:Insertwsdl#InsertData',
      'rpc',
      'literal',
      'Retrieve data from  the database'
      );
  
      function InsertData($data, $data1, $data2, $data3, $data4){
  
          $db_host = '127.0.0.1';
          $db_username = 'sample';
          $db_password = '' ;
          $db_name = 'sample';
  
          $conn = new mysqli($db_host, $db_username, $db_password, $db_name);
  
          if ($conn-&gt;connect_error) {
              trigger_error('Database connection failed: ', $conn-&gt;connect_error, E_USER_ERROR);
          }
  
          $sql = "SELECT * FROM sample_transaction ";
  
          $query = $conn-&gt;query($sql);
  
          if ($query-&gt;num_rows &gt; 0) {
              while ($row = $query-&gt;fetch_assoc()) {
                  echo "&lt;br /&gt; Data : " .$row['data'];
                  echo "&lt;br /&gt; Data1 : " .$row['data1'];
                  echo "&lt;br /&gt; Data2 : "  .$row['data2'];
              }
  
          } else {
              echo "0 Results";
          }
      }
  
      $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA : '' ;
      $server-&gt;service($HTTP_RAW_POST_DATA);
  ?&gt;
  </code></pre>
  
  <p><strong>webservice_client.php</strong></p>
  
  <pre><code>&lt;?php
  require_once('lib/nusoap.php');
  
  $data = json_decode(file_get_contents("php://input"), true);
  
  
  $data = $data['data'];
  $data1 = $data['data1'];
  $data2 = $data['data2'];
  $data3= $data['data3'];
  $data4 = $data['data4'];
  $client = new nusoap_client('http://sampleserver:8544/Nusoap/webservice_server.php?wsdl', true);
  
  $datas = array(
       'data' =&gt; $data,
      'data1' =&gt; $data1,
      'data2'=&gt; $data2,
      'data3' =&gt; $data3,
      'data4' =&gt; $data4,  
      );
  
  $result= $client-&gt;call('InsertData', $datas);
  
  print_r($result);
  
  echo "&lt;br /&gt;&lt;pre&gt;" .$client. "&lt;/pre&gt;";
  echo "&lt;h2&gt;Request&lt;/h2&gt;";
  echo "&lt;pre&gt;" .htmlspecialchars($client-&gt;request, ENT_QUOTES). "&lt;/pre&gt;";
  echo "&lt;h2&gt;Response&lt;/h2&gt;";
  echo "&lt;pre&gt;" .htmlspecialchars($client-&gt;response, ENT_QUOTES). "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>I just comment out the <code>$server-&gt;soap_defencoding</code> because the response will have a content-type like <code>text/xml charset=utf-8</code> if not comment out. Is it also a problem if I don't have the same content-type, the charset I mean? Base on the codes I posted above how can I solve this issue because I been looking for solution for this in 2 days. Can someone point out where did I go wrong and how can I solve this? By the way, the code will just select from the database, it retrieves only few data from the database and got that error.
  Any help is appreciated. Thanks a lot.</p>