0

I have followed this Question to write the web-service call. but controller is not showing it says 404 Not Found.

<?php

namespace Autosynch\synchProduct\Controller\Page;
use Magento\Framework\HTTP\Client\Curl;
use \Magento\Framework\App\Helper\AbstractHelper;

class Service extends AbstractHelper {
        /**
        * @var \Magento\Framework\HTTP\Client\Curl
        */
        protected $_curl;

        public function __construct(Curl $curl) 
        {

            $this->_curl =$curl;
        }
         /**
         * Send SMS
         * @param type $mobile_no
         * @param type $body
         */
        public function getResponse($url)
        {
          $url = urlencode($url);  
          $this->_curl->get($url);
          $response = $this->_curl->getBody();

         return $response;
        }

        public function execute()
        {
            echo "Welcome to Service Call";
        }

}

\app\code\Autosynch\synchProduct\etc\frontend\routes.xml

<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="Autosynch" frontName="auto">
            <module name="Autosynch_synchProduct" />
        </route>
    </router>
</config>

after trying below answer i am getting below error:

1 exception(s):
Exception #0 (Exception): Strict Notice: Declaration of Autosynch\synchProduct\Controller\Page\Service::getResponse() should be compatible with Magento\Framework\App\Action\AbstractAction::getResponse() in C:\xampp\htdocs\Magento-CE\app\code\Autosynch\synchProduct\Controller\Page\Service.php on line 40

Exception #0 (Exception): Strict Notice: Declaration of Autosynch\synchProduct\Controller\Page\Service::getResponse() should be compatible with Magento\Framework\App\Action\AbstractAction::getResponse() in C:\xampp\htdocs\Magento-CE\app\code\Autosynch\synchProduct\Controller\Page\Service.php on line 40
#0 C:\xampp\htdocs\Magento-CE\vendor\composer\ClassLoader.php(444): Magento\Framework\App\ErrorHandler->handler(2048, 'Declaration of ...', 'C:\\xampp\\htdocs...', 40, Array)
#1 C:\xampp\htdocs\Magento-CE\vendor\composer\ClassLoader.php(444): Composer\Autoload\includeFile()
#2 C:\xampp\htdocs\Magento-CE\vendor\composer\ClassLoader.php(322): Composer\Autoload\includeFile('C:\\xampp\\htdocs...')
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass('Autosynch\\synch...')
#4 [internal function]: spl_autoload_call('Autosynch\\synch...')
#5 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\App\Router\ActionList.php(91): is_subclass_of('Autosynch\\synch...', '\\Magento\\Framew...')
#6 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\App\Router\Base.php(295): Magento\Framework\App\Router\ActionList->get('Autosynch_synch...', NULL, 'page', 'service')
#7 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\App\Router\Base.php(161): Magento\Framework\App\Router\Base->matchAction(Object(Magento\Framework\App\Request\Http), Array)
#8 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\App\FrontController.php(50): Magento\Framework\App\Router\Base->match(Object(Magento\Framework\App\Request\Http))
#9 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#10 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#11 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
#12 C:\xampp\htdocs\Magento-CE\vendor\magento\module-store\App\FrontController\Plugin\RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#13 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#14 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#15 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#16 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#17 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#18 C:\xampp\htdocs\Magento-CE\vendor\magento\module-page-cache\Model\App\FrontController\BuiltinPlugin.php(73): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#19 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#20 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#21 C:\xampp\htdocs\Magento-CE\vendor\magento\module-page-cache\Model\App\FrontController\VarnishPlugin.php(55): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#22 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\Interception\Interceptor.php(142): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#23 C:\xampp\htdocs\Magento-CE\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#24 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#25 C:\xampp\htdocs\Magento-CE\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#26 C:\xampp\htdocs\Magento-CE\index.php(41): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#27 {main}
0

Your code should be like this:

<?php
namespace Autosynch\synchProduct\Controller\Page;
use Magento\Framework\HTTP\Client\Curl;

class Service  extends \Magento\Framework\App\Action\Action {
        /**
        * @param \Magento\Framework\App\Action\Context $context
        * @param \Magento\Framework\HTTP\Client\Curl $curl
        */
        protected $_curl;

        public function __construct(
            \Magento\Framework\App\Action\Context $context,
            Curl $curl
        ) 
        {

            parent::__construct($context);
            $this->_curl =$curl;
        }
         /**
         * Send SMS
         * @param type $mobile_no
         * @param type $body
         */
        public function getMyCurlResponse($url)
        {
          $url = urlencode($url);  
          $this->_curl->get($url);
          $response = $this->_curl->getBody();

         return $response;
        }

        public function execute()
        {
            echo "Welcome to Service Call";
        }

}

You should extend this class \Magento\Framework\App\Action\Action.

4
  • it looks same after adding this also. i will check again after Setup:upgrade – JB Pakalapati May 27 '18 at 6:34
  • have you added route in routes.xml? – kunj May 27 '18 at 6:36
  • Yes, Please check the question updated – JB Pakalapati May 27 '18 at 6:43
  • I have updated my answer, you are getting that error because we have used same method getResponse which Magento using in vendor/magento/framework/App/Action/AbstractAction.php. – kunj May 27 '18 at 6:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.