3

enter image description hereI'm accessing my controller via postman tool (Postman)

I've passed custom header as shown in image and trying to access it in controller through this code:

$this->_response->getHeader('APP_ID');

but it returns no data. Please Help.

3 Answers 3

2

Finally, got the solution

$httpRequestObject = new \Zend_Controller_Request_Http();
$httpRequestObject->getHeader('APP_ID');

Thank you!

3
  • I am using POSTMAN for rest api, How can i get my oAuth 2 details, now i have all my oAuth 1 details as well as working, now we decide to move oAuh 2, so that how can i get my oAuth 2 details? @ Manish Joy
    – zus
    Commented Oct 30, 2018 at 6:05
  • Hello, i have same requirement please share full code
    – devhs
    Commented May 19, 2021 at 10:19
  • @devhs please check the solutions given below. Its explained there.
    – Manish Joy
    Commented May 25, 2021 at 6:48
2

As long as your controller is a child of AbstractAction you can also access this data by request instance: $this->getRequest()->getHeader('APP_ID')

1
  • I'm not sure why this was initially downvoted, as this worked perfectly for me! There may be situations where $this->getRequest() isn't available, so include the class \Magento\Framework\App\RequestInterface in your constructor, as explained here: mage2.pro/t/topic/235
    – Smithee
    Commented Nov 11, 2019 at 11:29
0

Remember that All caps HTTP headers with underscores dropped in Apache 2.4.

Nginx:

http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers

So we can try add other values. For example: AppId without underscores.

We could get the header with

\Magento\Framework\App\RequestInterface

\Magento\Framework\Webapi\Request

\Magento\Framework\HTTP\PhpEnvironment\Request

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.