4

I'm trying to POST data using command line using curl.

curl -v POST -d ' { "data1": "sample1", "data2": "sample2" } ' -H "Content-Type: application/json" -H "Authorization: BASIC vkslnkg561mZEqCq3l3RglAOAZ7d8XBeg2VjIAyC" http://localhost/Bowling/public/api/foo

I'm using Laravel 5, is there any way to get the Authorization token and the data passed in routes/controller?

Right now Im using

getallheaders();

I'm able to get Authorization token but not the data { "data1": "sample1", "data2": "sample2" }

Deepak Bandi
  • 1,854
  • 4
  • 21
  • 37

2 Answers2

2

In Laravel 5 JSON data can be fetched with

$request->json()->all()

See this answer Posting JSON To Laravel

Community
  • 1
  • 1
thomas.g
  • 3,894
  • 3
  • 29
  • 36
2

Finally found a solution for this: file_get_contents("php://input")

Route::any('api/foo', function(){   
    $allHeaders = getallheaders();  

    return (file_get_contents("php://input"));
    /* Rest of the code */
});
Deepak Bandi
  • 1,854
  • 4
  • 21
  • 37