VerticalTab / Pillow

MIT License
21 stars 3 forks source link

XML Error class HttpClient fsockopen problem #5

Open ghost opened 8 years ago

ghost commented 8 years ago

When using the API to get data for these properties and various others:

Address, Zip 19385 Cypress Ridge Terrace, 20176 10 Glen Ave, 02896

Returns various chars in the body string. Not sure what is going but simplexml_load_string fails due to the chars in the string. If I remove the fsockopen and use php's file_get_contents all is fine and works wonderfully. Below you can see what I did to get it work on my end if you like I can make a pull request with the code change?

verticaltab/pillow/src/VerticalTab/Pillow/HttpClient.php : line 27 /**

/* $fp = @fsockopen($this->host, 80, $errno, $errstr); if(!$fp) { $msg = "Failed to open connection {$this->host} $errno $errstr"; throw new Exception($msg); }

fwrite($fp, $this->buildHeader($url));
$headerFound = false;
while(!feof($fp)) {
  $line = fgets($fp);
  if($line === "\r\n") {
    $headerFound = true;
    $line = '';
  }
  if($headerFound) {
    $body .= $line;
  }
}
fclose($fp);
$body = substr( $body, strpos($body, '<?xml'));

*/ $body = file_get_contents('http://'.$this->host.$url); echo $body.PHP_EOL; $xml = @simplexml_load_string($body); if(!$xml) { throw new Exception('Unable to load xml result'); }

return $xml;

}