add authorization for http
This commit is contained in:
parent
e5680bb350
commit
189c866f58
@ -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<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
Future<void> _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<String, String> 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(() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user