0

Its true that this question already exists. But thought of posting it anyway as couldnt find the solutions helpful.

I am using an url to connect to an endpoint. And the url has '<','>' character in it. Like https://www.domain.com?filter=(order_number>2000).

When i am trying to use this url i am getting Invalid URI supplied error. Here is the code

 /**
     * @return object
     * @throws \Zend_Http_Client_Exception
     */
    private function getZendHttpClient()
    {
        $client = new \Zend_Http_Client();
        $client->setUri('https://www.domain.com?filter=(order_number>2000)'); // Here is the error
        $client->setConfig($this->getSSLConfig());
        $client->setMethod(\Zend_Http_Client::GET);
        $client->setHeaders($this->getHeader()); // Getting the header here
        return $client;
    }

    /**
     * Setting SSL check off in production not desirable. Needs to be removed.
     * @return array
     */
    private function getSSLConfig() : array
    {
        $config = array(
            'adapter'     => '\Zend_Http_Client_Adapter_Curl',
            'curloptions' => [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]
        );
        return $config;
    }

Now the issue is magento2 creates an instance of Zend_Uri_Http which checks for all the possible characters which can be inside an url and '>','<' cant be there. Inside Zend_Uri_Http magento2 has defined all the characters which can be inside an url. I need to override it to add '>','<'.

Now 1 option can be like

i) create new class A which will extend Zend_Http_Client. Use class A instead of Zend_Http_Client.

ii) Now create new class B which will extend Zend_Uri. And use class B inside class A.

iii) Create a new class C which will extend Zend_Uri_Http. And use class C inside class B.

But this is too much for a little change. I'm sure there would some better and short approach.

  • why you don't use PHP curl? instead of zend_client – Amit Bera Sep 23 at 8:19
  • I can. But wanted to use something which magento uses by default. By the way i,m actually using Zend_Http_Client_Adapter_Curl adapter which in turn uses cURL. – Kingshuk Deb Sep 23 at 8:25
  • ii) Now create new class B which will extend Zend_Uri. And use class B inside class A. and it is best solution for my mind. – Amit Bera Sep 23 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.