I am new to ionic2 and a bit confused about the best approach to retrieve the request send from app to a php file..
I am integrating my app with laravel PHP framework .. Currently I am able to access request if using
$postdata = file_get_contents("php://input");
Here I am posting data to php server using ionic2:
this.http.post('http://localhost/lara/blog/public/api/apis/login', JSON.stringify({email: email,password: password}), { headers: headers }).map(res => res.json()).subscribe(data => {
});
public function apiLogin(Request $request)
Actually the issue is that when using postman I am able to get request in $request but when sending from ionic2 I am not getting it in $request but getting in $postdata..
So whats the correct way to retrieve in PPH or if I am sending it in a wrong way ..
Can any one please suggest?
You are getting in $postData because you are basically sending json data. Check here about reading json post request
you are setting body as:
JSON.stringify({email: email,password: password})
so header becomes: 'Content-Type': 'application/json'
You can set
'Content-Type':'application/x-www-form-urlencoded'
and body as:
"email="+email+"&password="+password
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.