i'm making an app in Flutter and i need to send a cookie on the header to access my web API.
However, i'm not having any sucesss.
Here is my code. How can i persist a Cookie in flutter?
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
class XsrfToken {
static Future<String> getXsrf(String getJwt) async {
var url = 'https://www.myservice.com/api/v1/api.php';
var decode = json.decode(getJwt);
var header = {"Content-Type": "application/json"};
Map params = {"token": decode};
var _body = json.encode(params);
var response = await http.post(url, headers: header, body: _body);
print('Responde status ${response.statusCode}');
print('Responde body ${response.body}');
var xsrf = response.body;
var prefs = await SharedPreferences.getInstance();
prefs.setString("TokenXSRF", xsrf);
return xsrf;
}
}