Skip to content
Snippets Groups Projects
Commit 7971b505 authored by Maximilian Betz's avatar Maximilian Betz
Browse files

login and getting token is working

parent 74cb1e4c
No related branches found
No related tags found
No related merge requests found
...@@ -11,11 +11,13 @@ Future<int> login() async { ...@@ -11,11 +11,13 @@ Future<int> login() async {
String url = 'https://sandbox.sensor.awi.de/rest/sensors/contacts/login'; String url = 'https://sandbox.sensor.awi.de/rest/sensors/contacts/login';
debugPrint("Start login to : " + url); debugPrint("Start login to : " + url);
final String body = jsonEncode(configuration.loginInformation); // New Test: https://stackoverflow.com/questions/58197496/flutter-post-login-with-email-and-password-with-content-type-application-x-www-f
debugPrint(body); Map<String, dynamic> body = {'username': configuration.loginInformation.mail, 'authPassword': configuration.loginInformation.password};
String encodedBody = body.keys.map((key) => "$key=${body[key]}").join("&");
debugPrint(encodedBody);
final response = await http.post(Uri.parse(url), final response = await http.post(Uri.parse(url),
body: body, body: encodedBody,
headers: { headers: {
'Accept' : 'application/json', 'Accept' : 'application/json',
'Content-Type' : 'application/x-www-form-urlencoded' 'Content-Type' : 'application/x-www-form-urlencoded'
...@@ -23,9 +25,14 @@ Future<int> login() async { ...@@ -23,9 +25,14 @@ Future<int> login() async {
encoding: Encoding.getByName("utf-8") encoding: Encoding.getByName("utf-8")
); );
if (response.statusCode == 200) { if (response.statusCode == 200) {
debugPrint('Login success'); debugPrint('Login success');
debugPrint(response.body.toString());
debugPrint(response.headers.toString());
debugPrint(response.headers['set-cookie']);
//TODO store token //TODO store token
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment