how to solve flutter dio connection timeout error - flutter

I/flutter (16260): DioError [DioErrorType.DEFAULT]: HttpException: Connection closed while receiving data, uri="URL".
I got this error while I post a req to the PHP backend which generate a file link .and send back the link as the response it takes about 5 seconds and more in postman. is there is any way to solve this problem with dio package or some other

Related

Flutter http request to proxied rest Api

I put proxy on my Rest API in cloudflare.
Then whenever I try to make an http request, I get this error:
I/flutter (30668): HandshakeException: Handshake error in client (OS Error:
I/flutter (30668): SSLV3_ALERT_HANDSHAKE_FAILURE(tls_record.cc:594)
I/flutter (30668): HANDSHAKE_FAILURE_ON_CLIENT_HELLO(handshake.cc:644))
When I remove it, all request pass. But I need the proxy.
How do I handle this, please?

Connection closed before full header was received in flutter app with apollo server as backend

Created an flutter app with typegraphql and apollo server in backend. Application works fine. But at random times it throws an error,
OperationException(linkException: ServerException(originalException: Connection closed before full header was received, parsedResponse: null), graphqlErrors: [])

flutter: DioError [DioErrorType.response]: XMLHttpRequest error

I created an app and test it on emulator and andriod phone, i am using api's and nodejs based backend and mongodb database. it works fine when i test it on devices, but when i run it on chrome it sends me this error.
Error:
Error: Unsupported operation: NetworkInterface.list
DioError [DioErrorType.response]: XMLHttpRequest error.
here is my dio request code
Code:
calltimeInApi() async {
Dio dio=new Dio();
var data={
'username': getname,
'token': getaccesstoken,
};
timeOutButtonPressed=true;
await dio
.post(localhostUrlTimeIn,data: json.encode(data))
.then((onResponse)async {
getapitimein=onResponse.data['TimeIn'];
}).catchError((onerror){
print(onerror.toString());
});
}
please help where i am doing wrong!
There doesn't seem to be any issues on the code snippet that you've shared. If the HTTP Requests works fine on mobile devices but not on web, I suggest check the logs if you're getting CORS errors. A quick workaround on this issue is by running the web app with html renderer in debug.
flutter run -d chrome --web-renderer html

HTTP request failed, statusCode: 404 in flutter when load from local image

My Flutter app does not read photos from Local and gives me a 404 error
this is my eroor:
HTTP request failed, statusCode: 404, http://192.168.1.105/flutter_app3Images/dark.jpg
this is my code:
It was my problem:
I instead:
Image.asset(proudocts[index].img_url),
I wrote:
Image.network()"http://192.168.1.105/flutter_app3"+proudocts[index].img_url),

Flutter - How to get api response from a certification errored link

I'm trying to get an api from www.mocky.io, the issue is, when the app starts I'm getting an error like
E/flutter ( 846): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter ( 846): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))
this is how I'm getting the response.
Future _fetchPost() async {
http.Response response = await http.get(url);
print(response.body);
setState(() {
var convertDatatoJson = json.decode(response.body);
debugPrint(convertDatatoJson.toString());
_data = convertDatatoJson['table_menu_list'];
});}
How can I verify the certificate for this api link for GET method?
I referred this issue, for POST method https://stackoverflow.com/a/54359013/11893608,
any other suggestions would be helpful
Change https to http
it will Resolve your Issue
Use this : http://www.mocky.io/v2/5dfccffc310000efc8d2c1ad
Try adding both http and www.
Example:
http://www.mocky.io/v2/5185415ba171ea3a00704eed
mocky.io may be using www to differentiate between subdomains. That is why its not worked when adding http only.