I have a PHP laravel backend running with Auth. How can I log in from flutter?
I tested it registering and logging in with laravel blade views, and then with a simple HTML form and it worked. I'm trying to log in from my flutter app now but always get the same exception:
"SocketException: OS Error: Connection Refused, errno = 111, address = 127.0.0.1, port = 41978"
Except for the port increments each time I try.
I did this simple call first from a file in my desktop and successfully logged in:
<form method="POST" action="http://127.0.0.1:8000/login">
<input id="email" name="email" type="email" />
<input id="password" name="password" type="password" />
<button type="submit">login</button>
</form>
This is my flutter HTTP request code:
http.Response webMessage;
webMessage = await http.post('http://127.0.0.1:8000/login',
body: {
'email': myUser,
'password': myPass,
},
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Content-Type': 'application/x-www-form-urlencoded'
},
encoding: Encoding.getByName('utf-8'),
).timeout(_timeout);
I also tried with Accept and Content-Type: 'application/json'. Sending a string, a Map.
I also set this in VerifyCsrfToken Middleware:
protected $except = [
'login',
];
I expect the request to successfully log the user in, and respond with a session and token cookie, to use in future requests.
Thanks!