Questions tagged [dart-http]

Use this tag for questions relating to the Dart programming language http package.

The http package is used to make HTTP requests.

More information can be found at the http package listing on dartlang.org

80 questions
19
votes
1 answer

Difference between http and HttpClient in Dart

I'm trying to understand the difference between the http package and the HttpClient class in the dart:io library. My purpose is to known when I should use which. I see both of them used to apparently do the same thing. I've seen these…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
19
votes
3 answers

How to get progress event while uploading file on http.MultipartRequest request in flutter

I am uploading a file using MultipartRequest from package:http. I am successfully uploading the file but I want to get the progress of the file that is being uploaded. How can I achieve that? My current code looks something like this Future…
Aawaz Gyawali
  • 3,244
  • 5
  • 28
  • 48
16
votes
4 answers

SocketException: Failed host lookup: ‘...com’ (OS Error: nodename nor servname provided, or not known, errno = 8)

We are in a situation where the production app is facing the following socket exception and not able to perform any other network operation after this.  DioError [DioErrorType.DEFAULT]: SocketException: Failed host lookup: ‘xyz.abc.com’ (OS Error:…
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
14
votes
2 answers

Optimal way to make multiple independent requests to server in Dart

I want to make to multiple requests to same server in an optimal way. So I have Future> getAllItems() async { var client = new http.Client(); List itemsIds = ['1', '2', '3']; //different ids List itemList = []; …
Sabith
  • 185
  • 2
  • 3
  • 10
13
votes
4 answers

How to catch SocketException using the http library?

This problem has already been pointed out by others (like here). Althought I may have understood the cause, I still haven't found a solution when using the higher-level http library. For example: import 'package:http/http.dart'; // yes, pwd is…
devrocca
  • 2,497
  • 2
  • 19
  • 27
13
votes
2 answers

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

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…
gabbar0x
  • 4,046
  • 5
  • 31
  • 51
10
votes
3 answers

Dart http: "Bad state: Can't finalize a finalized Request" when retrying a http.Request after fetching a new access token

I'm currently trying to access a Web API in Flutter that requires a JWT access token for authorization. The access token expires after a certain amount of time. A new access token can be requested with a separate refresh token. Right now this…
boformer
  • 28,207
  • 10
  • 81
  • 66
7
votes
1 answer

Downloading progress in dart:http

I'm trying to make a progress bar indicator for a downloading file, but if I add a listener to the StreamedResponse, the piping works, but does to not finish its future. final client = new http.Client(); http.StreamedResponse response = await…
Evaldo Bratti
  • 7,078
  • 2
  • 18
  • 19
7
votes
1 answer

Flutter add self signed certificate from asset folder

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…
Siddharth jain
  • 447
  • 1
  • 5
  • 13
7
votes
3 answers

Convert String to GET request Parameter in Dart using standard library

I have a multiword String that I'd like to convert to a GET request parameter. I have an API endpoint /search that takes in the parameter query. Now typically your request would look like http://host/search?query=Hello+World. I have a String Hello…
gabbar0x
  • 4,046
  • 5
  • 31
  • 51
6
votes
4 answers

Flutter: Http post request Error Invalid media type: expected

I am making an http post request using http dependency. I am facing the below error in my response. I am posting my code below: flutter: Error on line 1, column 32: Invalid media type: expected /[^()<>@,;:"\\\/[\]?={} \t\x00-\x1F\x7F]+/. ╷ …
Achin
  • 1,252
  • 4
  • 28
  • 63
5
votes
1 answer

fetching the response from API and dealing with the errors / converting Bytestreem to Map in flutter

I am trying to communicate with a PHP backend using API but I can not reach the body of the response. I got the base code from the postman. And here is the data of the body response: I need to reach the message, and the errors to show them in the…
Mohammad Rabiee Nasri
  • 1,309
  • 2
  • 7
  • 26
5
votes
2 answers

How to manage blocs thrown exceptions with StreamBuilder?

I'm trying to return a snapshot error state to my StreamBuilder when my provider has problems during the http.get() call. In my case I throw an exception when the the http.get() return a state different from 200 (OK). I would like to be able to…
E.Benedos
  • 1,585
  • 14
  • 41
5
votes
1 answer

How can I use shelf_web_socket to listen for http and ws requests on the same port

https://pub.dartlang.org/packages/shelf_web_socket shows this example import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:shelf_web_socket/shelf_web_socket.dart'; void main() { var handler = webSocketHandler((webSocket) { …
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
4
votes
2 answers

Flutter add client certificate to request using http.dart

I'm trying to load a client certificate to a http.client from the http.dart package. I'v seen multiple answers on how to do it using the HttpClient class, like this answer: Flutter add self signed certificate from asset folder, which basicaly…
Yonatan
  • 323
  • 3
  • 10
1
2 3 4 5 6