这是我的 AngularJS 控制器:
app.controller('emailConfirmCtrl', function ($scope, $http) {
$scope.check_credentials = function () {
var request = $http({
method: 'POST',
url: 'api/slim.php/website/email_verification',
data: {
email: 'email@abc.com'
},
headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8' }
});
/* Check whether the HTTP Request is successful or not. */
request.success(function (data) {
console.log('email sent successfully');
console.log(data);
});
}
});
在我的 Slim API 中,我正在尝试访问这样的数据:
$app->post("/website/email_verification", function () use ($app, $db) {
$request = $app->request();
$body = json_decode($request->getBody());
// $email_id = $body['email'];
echo $body;
});
但是我得到错误404,但是如果我改变post方法得到那么没有404错误(即AngularJS控制器中给出的url很好)。
如何使用post方法访问SLIM API中的email_id。
答案 0 :(得分:1)
$app->post(
'/login',
function () use ($app) {
$app->response()->header("Content-Type", "application/json");
$post = json_decode($app->request()->getBody());
$postArray = get_object_vars($post);
$login = $postArray['login'];
$pass = $postArray['pass'];
答案 1 :(得分:0)
对于json,您可以阅读原始请求正文
您将解码输入流
ToList()
在你的情况下你可以尝试这个
GetBool1()