Closed leehung-net closed 7 years ago
What's in $_POST
?
Hi samdark, $_POST= {array}[0]
Means no data was received by PHP.
How about Yii::$app->request->getRawBody()
?
Hi samdark, Thank for answer. I resolve this issue, it is problem cross domain of apache.
Hi all, I have using framework for my backend and create a module api restful. my frontend use angular-cli, when i make a request login as below:
var data = "username=username2&password=123456";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "http://esl.com/backend/web/api/user/login");
xhr.setRequestHeader("authorization", "Basic dXNlcm5hbWUyOjEyMzQ1Ng==");
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
On Api I use code as below get post data:
$post = \Yii::$app->request->post();
But all request had $post = array empty use postman is ok