0

I'm having trouble using Zend HTTP on a URL:

$client = new Zend_Http_Client('http://xxfire_killumiex.api.channel.livestream.com/2.0/info.json');
$feed = $client->request()->getBody();

For some reason, this gives me an error...

Invalid URI supplied

Whats wrong this this specific url?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jason Axelrod
  • 7,155
  • 10
  • 50
  • 78

1 Answers1

2

Whats wrong this this specific url?

The underscore.

From RFC 1912

Allowable characters in a label for a host name are only ASCII letters, digits, and the `-' character.

Edit

After doing some more reading, it seems that Zend may be wrong in this case.

See Can (domain name) subdomains have an underscore "_" in it?

According to ZF-9671, you might be out of luck, though I've re-opened the issue.

My suggestion in the meantime; Create your own HTTP client class like this

class My_Http_Client extends Zend_Http_Client
{
    public function validateHost($host = null)
    {
        if ($host === null) {
            $host = $this->_host;
        }

        // If the host is empty, then it is considered invalid
        if (strlen($host) === 0) {
            return false;
        }

        return true;
    }
}
Community
  • 1
  • 1
Phil
  • 157,677
  • 23
  • 242
  • 245
  • I ran a str_replace to replace it with %5F, it didn't make a difference. Underscores are valid URI characters anyways, so why would it be an issue? – Jason Axelrod Mar 15 '11 at 22:14
  • @Jason here is a regex that ZF uses to validate URI `preg_match('/^[0-9.a-e:.]*$/i', $value)` – criticus Mar 15 '11 at 22:19
  • I can replace it with %5F, I can run rawurlencode() on it... doesn't make a difference... still gives the same error. – Jason Axelrod Mar 15 '11 at 22:19
  • @criticus That's the IP address schema validation. The hostname validation pattern found in `Zend_Validate_Hostname` is `/^[a-z0-9\x2d]{1,63}$/i` – Phil Mar 15 '11 at 22:29
  • @Jason You can replace it with whatever you want but unless it contains only letters, digits or hyphen, it will fail – Phil Mar 15 '11 at 22:30
  • umm... no. Thats not how Zend_Http_Client works... the following url works perfectly fine `http://xifcsxswx.api.channel.livestream.com/2.0/info.json`. If it could only have letters digits and hyphens, then you couldn't have slashes or periods. This is a URL, not a string. – Jason Axelrod Mar 15 '11 at 22:38
  • @Jason Take note that I'm only referring to the **hostname** part. I've found some more information though and will add it to my answer – Phil Mar 15 '11 at 22:43