Problem when logging into the website using post in dart/flutter

251 Views Asked by At

I encountered a problem when logging into the website using package: http. When I use

import 'package:http/http.dart';

void main(List<String> arguments) async {
  var client = Client();
  var url = 'https://shop.ezskin.com.tw/account/login';
  var payload = {
    'customer[email]': 'test123',
    'customer[password]': 'test1234',
  };
  var response = await client.post(url, body: payload);

  print(response.statusCode);
  print(response.body);
}

response.statusCode shows 302, which means redirect, but response.body shows

<html>
  <body>You are being <a href="https://shop.ezskin.com.tw/account/index">redirected</a>.
  </body>
</html>

Results don't go to account details page as expected. After that I use client.get

var nextPage = await client.get('https://shop.ezskin.com.tw/account/index');

print(nextPage.body);

It goes back to the account login page.

  1. So how can I correctly redirect to the account details page after login?
  2. I thought that after using Client(), once I logged in correctly, before using Client.close(), making multiple requests to the same server is feasible, but the result does not seem to be the case. Is it something I did wrong?

  3. In addition, should I encrypt the email and password before putting them in the parameter list?

0

There are 0 best solutions below