Zend HTTP Client Invalid URI?

2019-09-06 00:50发布

问题:

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?

回答1:

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;
    }
}