How to get POST data with a swirl?

I am trying to execute POST data using the 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 am using Laravel 5, is there any way to get the authorization token and the data transferred in the routes / controller?

I'm using now

getallheaders();

I can get the authorization token, but not the data {"data1": "sample1", "data2": "sample2"}

+4
source share
2 answers

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 */
});
+1
source

In Laravel 5, JSON data can be obtained using

$ request-> JSON () -> all ()

See this answer Posting JSON To Laravel

+2

Source: https://habr.com/ru/post/1613430/


All Articles