Flutter CachedNetworkImage uses NetEase Cloud link 403 error solution
Error message
Still the familiar error
======== Exception caught by image resource service ================================================
The following HttpExceptionWithStatus was thrown resolving an image codec:
HttpException: Invalid statusCode: 403, uri = https://p1.music.126.net/q7UebOEf7TUkQ_NhBZSNlg==/109951167926630292.jpg?param=512y512
When the exception was thrown, this was the stack:
Image provider: CachedNetworkImageProvider("https://p1.music.126.net/q7UebOEf7TUkQ_NhBZSNlg==/109951167926630292.jpg?param=512y512", scale: 1.0)
Image key: CachedNetworkImageProvider("https://p1.music.126.net/q7UebOEf7TUkQ_NhBZSNlg==/109951167926630292.jpg?param=512y512", scale: 1.0): CachedNetworkImageProvider("https://p1.music.126.net/q7UebOEf7TUkQ_NhBZSNlg==/109951167926630292.jpg?param=512y512", scale: 1.0)
Solution
Click to view the source code of CachedNetworkImage
and then viewCachedNetworkImageProvider
foundStream<ui.Codec> _loadBufferAsync()
this method
ClickDefaultCacheManager
Jump to the relevant source code
ClickCacheManager
to jump, and then findFuture<FileInfo> downloadFile()
such a method
point turndownloadFile
method jump
point turn_downloadOrAddToQueue(url, key, authHeaders)
method jump
Point 击_updateFile(url, key, authHeaders: authHeaders))
Method
Point 击_download(cacheObject, authHeaders)
Method
ClickfileFetcher
This variable
ClickHttpFileService()
This method
ClickClient()
this method, and then jump to this page
ClickcreateClient()
, and then you can see the file paths of two implementation classesbrowser_client.dart
io_client.dart
Then we return to the previous page, which is the page justcreateClient()
, and look up at the header file
browser_client.dart
The file is modified as follows
FindFuture<StreamedResponse> send(BaseRequest request)
this method and add the following code
request.headers.remove("user-agent", "Dart/3.1 (dart:io)");
io_client.dart
The file is modified as follows
FindFuture<IOStreamedResponse> send(BaseRequest request)
this method and add the following code
ioRequest.headers.remove("user-agent", "Dart/3.1 (dart:io)");
The repair is now complete