0

I am adding custom header in my request (sent from external app) to Joomla controller with a custom header added. How to retrieve the header in my controller?

I tried using below but it gives me null.

$token = $app->input->server->getString('Authorization');

Request captured shows the headers added.

D/OkHttp: Content-Type: application/x-www-form-urlencoded
D/OkHttp: Content-Length: 25
D/OkHttp: Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiJhZG1pbiIsImlhdCI6MTQ3MzYyMjQyOSwiZXhwIjoxNDc2MjE0NDI5fQ.l691z66kzWaEA6RP7schKk4-N6xvXzneAwvKQm-Cj8E
0

To help others facing similar issue:

It looks like Joomla or the server is simply ignoring the Authorization headers. Changing name of some other name will be a workaround for this.

0

You can use plain PHP to retrive request headers. No need to use Joomla objects. Use below code

$token =  getallheaders ();
print_r($token);

to retrive full request headers.

  • Your solution seems like a suitable solution for the question asked, but the quality of your post is definitely "low-value" on any/all Stack Exchange sites. Thank you for endeavoring to contribute, but whenever you post a solution, you are expected provide more than just a code-only answer. A "good" answer begins with a correct working solution, but it doesn't stop there. Please do your best to educate not only the person asking the question but thousands of future researchers as well. Please provide a sample output for context, a link to the php docs, and any other info you find relevant. – mickmackusa May 16 at 20:58
  • Please read How to Answer. I will not be voting to Recommend Deletion because I feel your post adds otherwise missing value to the page. Please take a moment to edit/improve your post. Doing so will make your post and this site more valuable to researchers and it just might land you your first upvote. Finally, please take the tour and earn your "Informed" badge. This will help you to understand how you can best interact in this community. – mickmackusa May 16 at 21:08
-2

You need to use a different method than jinput.

$app = JFactory::getApplication();
$headers = $app->getHeaders();

See:

https://api.joomla.org/cms-3/classes/JApplicationWeb.html#method_getHeaders

  • From API: Method to get the array of response headers to be sent when the response is sent to the client.. These are not headers sent from client to server, rather opposite. – Nagarjun Sep 22 '16 at 17:39
  • Under what method are you sending it to the controller if not via http? Are you using a CLI? – tonypartridge Sep 22 '16 at 17:46
  • I am using okHttp android client which uses http. – Nagarjun Sep 22 '16 at 18:17

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.