Created
March 3, 2023 15:49
-
-
Save preinpost/941efd33dff90d9f8c7a208da40c18a9 to your computer and use it in GitHub Desktop.
headers override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 에러의 원인 | |
// 따로 User-Agent 값을 추가하지 않으면 기본값으로 `Dart/<version> (dart:io)` 가 들어갑니다. | |
// (https://api.flutter.dev/flutter/dart-io/HttpClient/userAgent.html) | |
// 이 값을 지우고 브라우저에서 사용하는 값으로 바꿔줍니다. | |
// (브라우저 값이 아니면 네이버에서 차단하는걸로 보입니다) | |
// 방법 1. (local? override) | |
// [home_screen.dart] | |
// headers에 useragent 추가 | |
... | |
child: Image.network( | |
webtoon.thumb, | |
headers: const {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",}, | |
), | |
... | |
// 방법 2. (global override) | |
// [main.dart] | |
class MyHttpOverrides extends HttpOverrides { | |
@override | |
HttpClient createHttpClient(SecurityContext? context) { | |
return super.createHttpClient(context) | |
..userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'; | |
} | |
} | |
void main() { | |
HttpOverrides.global = MyHttpOverrides(); | |
runApp(const App()); | |
} | |
class App extends StatelessWidget { | |
const App({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: HomeScreen(), | |
); | |
} | |
} |
지금은 첫 번째 방법으로 안 되는 것 같아요. 제가 잘 못했는지 안 되는지 알 수가 없네요. 혹시 지금도 첫 번째 방법으로 되나요?
첫번째 방법은 안되고 두번째 방법으로 해결했습니다 감사합니다!!
첫번째 방법 됐습니다 감사합니다 ^^
ListView makeList(AsyncSnapshot<List<WebtoonModel>> snapshot) { return ListView.separated( separatorBuilder: (context, index) => const SizedBox( width: 40, ), scrollDirection: Axis.horizontal, itemCount: snapshot.data!.length, itemBuilder: (context, index) { print(index); var webtoon = snapshot.data![index]; return Column( children: [ Image.network( webtoon.thumb, headers: const {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",}, ), Text(webtoon.title), ], ); }, ); }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
감사합니다!!