From 189c866f58472e44e893be96bc5cd52e9700a9d7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 30 Aug 2022 21:52:30 +0200 Subject: [PATCH] add authorization for http --- covas_mobile/lib/main.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 6673588..ed1de44 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; +import 'dart:convert'; void main() { runApp(const MyApp()); @@ -54,9 +55,16 @@ class _MyHomePageState extends State { int _counter = 0; Future _incrementCounter() async { - var url = Uri.http("localhost:8083", "api/v1/token"); - var response = await http.get(url); - stderr.writeln('Response status: ${response.statusCode}'); + var url = Uri.parse("http://localhost:8083/api/v1/token"); + String credentials = "peter93:toto"; + Codec stringToBase64 = utf8.fuse(base64); + String encoded = stringToBase64.encode(credentials); + stderr.writeln('Basic $encoded'); + + var response = await http.get(url, headers: { + HttpHeaders.authorizationHeader: 'Basic $encoded', + }); + stderr.writeln('Response status: ${response.headers}'); stderr.writeln('Response body: ${response.body}'); setState(() {