-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error 404 when trying to download a file. #2084
Comments
Please provide a minimal reproducible example. |
Please format your code. You have configured the |
Yes. Sorry. I meant to get back here earlier. The code above is about the 20th version. Sorry to waste your time by opening this issue. |
Package
dio
Version
5.5.0
Operating-System
Windows
Output of
flutter doctor -v
Dart Version
3.2.3
Steps to Reproduce
Using a browser. I can login to a server. Navigate to file download. and download a .csv file.
However, when I use dio.download:
I can login succesfully.
I can navigate successfully.
But when I try to download the same csv file I get error 404 status code and the local file gets created with the html code for the 404.
I did successfully download a file from a test server that doesn't require authentication.
The authenticated server uses cookies authentication.
My Code is below.
`
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio/dio.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
const username = '[email protected]';
const password = 'monkey';
const baseUrl = 'https://require_basic_auth.com';
const endpointUrl = 'pricingdata/thumasteritems-current.csv?v=2';
const allpricesUrl = 'https://requires_basic_auth.com/current-pricing/';
const localsavePath = "new-thumasteritems-current.csv";
void main() async {
var dio = Dio(BaseOptions(
connectTimeout: const Duration(seconds: 10), // in ms
receiveTimeout: const Duration(seconds: 10),
sendTimeout: const Duration(seconds: 10),
responseType: ResponseType.plain,
followRedirects: true,
validateStatus: (status) {
return true;
})); // some dio configurations
dio.interceptors.add(CookieManager(CookieJar()));
//var firstResponse = await dio.get(baseUrl);
//print(firstResponse.statusCode);
var loginResponse = await dio.post(baseUrl,
data: FormData.fromMap({
'username': username,
'password': password,
})); // cookies are automatically saved
print(loginResponse.statusCode);
const endpointUrl = 'https://proof.ovh.net/files/1Mb.dat'; // test server - works.
try {
var dlresponse = await dio.download(endpointUrl, localsavePath);
print(dlresponse.statusCode);
print('Download complete!');
} catch (e) {
print('Error during download: $e');
}
}
`
Expected Result
I was expecting a file to be downloaded.
Actual Result
I local file gets created with the contents of Error 404 html.
The text was updated successfully, but these errors were encountered: