Here is my server side code: (I use Laravel framework)
// route
Route::post('get_login_api_token', 'Auth\LoginController@get_login_api_token')->middleware('cors');
public function get_login_api_token(Request $request){
return $request;
}
And here is three kind of requests:
#1:
fetch('https://back.pronexo.net/get_login_api_token', {
method: 'POST', // or 'PUT'
mode: 'no-cors',
body: JSON.stringify({cell_phone:'whatever', password:'whatever'}),
headers:{
'Content-Type': 'application/json',
},
}).then(res => console.log('OK'));
returns
[]
#2:
fetch('https://back.pronexo.net/get_login_api_token?cell_phone=whatever&password=whatever', {
method: 'POST', // or 'PUT'
mode: 'no-cors',
headers:{
'Content-Type': 'application/json',
},
}).then(res => console.log('OK'));
returns
{"cell_phone":"whatever","password":"whatever"}
#3:
Ok, as you can see, in the postman (request simulator) it works when when you pass parameters in the body
section (not as query string in the url). But why it doesn't work in the code? (you can try it in the console
tan of your browser). Any idea how can I make #1
working ?
EDIT: Noted that the header is different in the postman: