3

I'm executing following code in terminal.

curl GET http://www.example.com/v1/users -H "Content-Type:application/json" -H "Authorization: 12345678" 

How can I receive Authorization parameter in server side.

I tried with $_REQUEST,$_GET methods. Not worked. Please suggest.

1
  • 1
    Did you try getallheaders function? Commented Feb 10, 2017 at 3:49

1 Answer 1

2

Use function getallheaders() to fetch all HTTP request headers.

http://php.net/manual/en/function.getallheaders.php

And fetch result like this:

Array ( [User-Agent] => curl/7.35.0 [Host] => 127.0.0.1 [Accept] => */* [Content-Type] => application/json [Authorization] => 12345678 ) 
Sign up to request clarification or add additional context in comments.

7 Comments

I faced another problem If my url like curl GET http://www.example.com/v1/users?id=1&action=view -H "Content-Type:application/json" -H "Authorization: 12345678" then getallheaders() not giving Authorization details.
@Gowri I tried again and no problem. What are you got terminal output? By the way, command usage is curl [URL...], you should be remove GET.
Can you pls let me know, how can I pass variables in POST request along with headers using -d option. I googled but only headers receiving server. Not params.
Pass query string, e.g: curl http://www.example.com/v1/users -d 'id=1&name=Calos'
following is my complete url but not receving. Can you pls check. curl -X POST 'http://www.example.com/v1/users' -H 'Content-Type: application/json' -H 'Authorization: 12345678' -d 'param1=xxx&param2=xxx'
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.