0

I am passing "id" in headers & trying to get its value in custom script.

using below code

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance(); 
$response = $objectManager->get('Magento\Framework\App\ResponseInterface');
$request = $objectManager->get('Magento\Framework\App\Request\Http');  
print_r($request->getPost()); exit; 

But i am not getting any data..

any thoughts what i am missing ?

2
  • I have tried to send data from post man & get data in script but its empty.
    – devhs
    May 19, 2021 at 10:14
  • any thoughts on this ?
    – devhs
    May 19, 2021 at 10:18

1 Answer 1

2

Try below code

protected $request;

    public function __construct(
        \Magento\Framework\App\RequestInterface $request,

    ) {
        $this->request = $request;
    }

    
    public function getRequestTest() 
    {
        $requestParams = $this->request->getParams();
        //get values of current limit. If not the param value then it will set to 12
        $pageSize = ($this->request->getParam('pageSize'));
        $page = ($this->request->getParam('currentPage'));
    }

Using object manager

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance(); 
$response = $objectManager->get('Magento\Framework\App\ResponseInterface');
$request = $objectManager->get('Magento\Framework\App\RequestInterface');  
print_r($request->getParams());

get header

echo $request->getHeader('DK_ID');

or

$httpRequestObject = new \Zend_Controller_Request_Http();
$httpRequestObject->getHeader('DK_ID');
7
  • Hello, thanks for the answer, i have tried this code in script but i get empty array. Please have a look at this request awesomescreenshot.com/image/…
    – devhs
    May 19, 2021 at 10:34
  • I have updated code & check, i receive blank response. Is their any way i can check either then postman ?
    – devhs
    May 19, 2021 at 10:44
  • use Magento\Framework\App\RequestInterface
    – Devidas
    May 19, 2021 at 10:46
  • $request->getHeader('DK_ID'); like this
    – Devidas
    May 19, 2021 at 10:46
  • I mean using any other tool instead of postman ?
    – devhs
    May 19, 2021 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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