devs. I am running a local apache server. There are static Vue files and 'print' folder with some script. I am trying to send an http request from Vue (via axios) to 'print' folder.
I have tried to use vue-resourse to send data, but I had the same problem.
Here is a Vue method:
postData: function() {
const data = {
firstName: "John",
lastName: "Doe"
};
const config = {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
};
axios
.post("/print", data, config)
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
The index.php file from print folder:
<?php
$postBody = file_get_contents("php://input");
$postBody = json_encode($postBody);
echo 'Post: ',$postBody, ' here';
Here are some screensots from network tab (sorry for quality) I am not sure why devtools treats request like GET, but I use POST
When I log the response into console it looks like that. Here the response is actually POST. But the data is still missing.
Prview tab looks like that.
Request actually reaches the file, but $postBody
is simply an empty string. I guees the problem is that ("php://input")
does not get any input. When echo count($_POST)
0 is returned. Thanks for any help..