dart-http

Unable to make calls to Localhost using Flutter, random port being assigned to HTTP GET call

左心房为你撑大大i 提交于 2019-12-17 16:29:36
问题 I'm attempting to build a Flutter app where I'm required to make an HTTP call using the dart http library. So here's a snipped of the fu I use to make the call, import 'package:flutter/material.dart'; import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:http/http.dart' as http; Future<List> getData() async { List data = new List(); var httpClient = new HttpClient(); var request = await httpClient.get("localhost", 5000, '/search?query=hello'); var response = await

Flutter add self signed certificate from asset folder

a 夏天 提交于 2019-12-08 03:02:09
问题 My server provides a Self Signed certificate when calling its HTTPS API. I have the certificate file in the asset folder and referenced its path in pubspec.yaml I have tried passing the certificate to SecurityContext and then using that context to create an HttpClient . But the way I'm passing the certificate to SecurityContext is not working. Here is the code: Future<ByteData> getFileData(String path) async { return await rootBundle.load(path); } void initializeHttpClient() async { try {

Optimal way to request multiple APIs and store on SQLITE multiple tables

╄→гoц情女王★ 提交于 2019-12-02 08:38:09
Question is: how to store on sqlite? I mean how to store 2 APIs data on 2 tables? I have multiple APIs to get and store data on the cache. currently, I do it one by one, like this: button pressed(): await HelperDatabase1().storeRegister(_url, tokens); await HelperDatabase1().storeEquipmentReg(_url, tokens); ... It's slow down my app...So I decided do @günter-zöchbauer way. ( https://stackoverflow.com/a/50028061/9139407 ) But I don't understand How to store on SQLite in multiple tables. storeAll() used Future.wait void storeAll(String url, String token) async { final urlList = ['$url/nativeapi

Optimal way to make multiple independent requests to server in Dart

折月煮酒 提交于 2019-12-01 18:14:34
I want to make to multiple requests to same server in an optimal way. So I have Future<List<Item>> getAllItems() async { var client = new http.Client(); List<String> itemsIds = ['1', '2', '3']; //different ids List<Item> itemList = []; for (var item in itemsIds) { //make call to server eg: 'sampleapi/1/next' etc await client.get('sampleapi/' + item + '/next').then((response) { //Do some processing and add to itemList }); } client.close(); return itemList; } Now, the api calls are made one after other. But the api calls are independent of each other. Whats the best way to implement so as to

Optimal way to make multiple independent requests to server in Dart

╄→гoц情女王★ 提交于 2019-12-01 16:22:35
问题 I want to make to multiple requests to same server in an optimal way. So I have Future<List<Item>> getAllItems() async { var client = new http.Client(); List<String> itemsIds = ['1', '2', '3']; //different ids List<Item> itemList = []; for (var item in itemsIds) { //make call to server eg: 'sampleapi/1/next' etc await client.get('sampleapi/' + item + '/next').then((response) { //Do some processing and add to itemList }); } client.close(); return itemList; } Now, the api calls are made one