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:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@ -54,9 +55,16 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
int _counter = 0;
|
int _counter = 0;
|
||||||
|
|
||||||
Future<void> _incrementCounter() async {
|
Future<void> _incrementCounter() async {
|
||||||
var url = Uri.http("localhost:8083", "api/v1/token");
|
var url = Uri.parse("http://localhost:8083/api/v1/token");
|
||||||
var response = await http.get(url);
|
String credentials = "peter93:toto";
|
||||||
stderr.writeln('Response status: ${response.statusCode}');
|
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}');
|
stderr.writeln('Response body: ${response.body}');
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user