Try out the working demo on dartpad and httpbin.org/basic-auth to try out how to use
For more see my stackoverflow question and the reply
Try out the working demo on dartpad and httpbin.org/basic-auth to try out how to use
For more see my stackoverflow question and the reply
import 'dart:convert' as convert; | |
import 'package:http/http.dart' as http; | |
void main(List<String> arguments) async { | |
final urlHttpBin = Uri.https('httpbin.org', '/basic-auth/myuser/mypasswd'); | |
const base64Encoder = convert.Base64Encoder(); | |
var creds64 = base64Encoder.convert('myuser:mypasswd'.codeUnits); | |
// https://pub.dev/documentation/http/latest/http/Client-class.html | |
final client = http.Client(); | |
final request = http.Request('GET', urlHttpBin); | |
request.headers['Authorization'] = 'Basic $creds64'; | |
// https://pub.dev/documentation/http/latest/http/StreamedResponse-class.html | |
final streamedResponse = await client.send(request); | |
// https://pub.dev/documentation/http/latest/http/Response/fromStream.html | |
final response = await http.Response.fromStream(streamedResponse); | |
// https://pub.dev/documentation/http/latest/http/Response-class.html | |
print(response.body); | |
client.close(); | |
} |