From 7971b50560f26890c92860638be53d1ae9924b1d Mon Sep 17 00:00:00 2001
From: Maximilian Betz <Maximilian.Betz@awi.de>
Date: Tue, 8 Mar 2022 17:42:33 +0100
Subject: [PATCH] login and getting token is working

---
 lib/login.dart | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/login.dart b/lib/login.dart
index ad4ec37..4cb9efe 100644
--- a/lib/login.dart
+++ b/lib/login.dart
@@ -11,11 +11,13 @@ Future<int> login() async {
   String url = 'https://sandbox.sensor.awi.de/rest/sensors/contacts/login';
   debugPrint("Start login to : " + url);
 
-  final String body = jsonEncode(configuration.loginInformation);
-  debugPrint(body);
+  // New Test:  https://stackoverflow.com/questions/58197496/flutter-post-login-with-email-and-password-with-content-type-application-x-www-f
+  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),
-      body: body,
+      body: encodedBody,
       headers: {
         'Accept' : 'application/json',
         'Content-Type' : 'application/x-www-form-urlencoded'
@@ -23,9 +25,14 @@ Future<int> login() async {
       encoding: Encoding.getByName("utf-8")
       );
 
-
   if (response.statusCode == 200) {
     debugPrint('Login success');
+
+    debugPrint(response.body.toString());
+    debugPrint(response.headers.toString());
+    debugPrint(response.headers['set-cookie']);
+
+
     //TODO store token
 
   } else {
-- 
GitLab