Flutter CachedNetworkImage uses NetEase Cloud link 403 error solution

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

Please add image description
foundStream<ui.Codec> _loadBufferAsync()this method
Please add image description

ClickDefaultCacheManagerJump to the relevant source code

Please add image description

ClickCacheManager to jump, and then findFuture<FileInfo> downloadFile()such a method

Please add image description

point turndownloadFilemethod jump

Please add image description

point turn_downloadOrAddToQueue(url, key, authHeaders)method jump

Please add image description

Point 击_updateFile(url, key, authHeaders: authHeaders))Method

Please add image description

Point 击_download(cacheObject, authHeaders)Method

Please add image description

ClickfileFetcherThis variable

Please add image description

ClickHttpFileService()This method

Please add image description

ClickClient()this method, and then jump to this page

Please add image description

ClickcreateClient(), and then you can see the file paths of two implementation classesbrowser_client.dart io_client.dart

Please add image description

Then we return to the previous page, which is the page justcreateClient(), and look up at the header file

Please add image description

browser_client.dartThe 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)");

Please add image description

io_client.dartThe 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)");

Please add image description
The repair is now complete

Guess you like

Origin blog.csdn.net/qianxiamuxin/article/details/134754102