Skip to content
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

web int类型超出限制后 数据错误 #2334

Open
jiajialaixi opened this issue Nov 27, 2024 · 6 comments
Open

web int类型超出限制后 数据错误 #2334

jiajialaixi opened this issue Nov 27, 2024 · 6 comments
Labels
h: need more info Further information is requested p: dio Targeting `dio` package platform: web s: bug Something isn't working

Comments

@jiajialaixi
Copy link

Package

dio

Version

5.7.0

Operating-System

Web

Adapter

Default Dio

Output of flutter doctor -v

No response

Dart Version

3.5.3

Steps to Reproduce

1、在flutter-web请求接口
1732674392519

Expected Result

image

Actual Result

在dio获取到的数据与服务器返回的不一致 在android 端这个id 就没有任何问题
image
我使用flutter http: ^1.2.2 请求接口返回的数据就是正确的

@jiajialaixi jiajialaixi added h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 27, 2024
@AlexV525
Copy link
Member

与 Dio 无关。

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2024
@AlexV525 AlexV525 added i: out of support and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 27, 2024
@jiajialaixi
Copy link
Author

jiajialaixi commented Nov 27, 2024

我的意思并不是获取精度问题 ,服务器返回的数据与dio 断点获取到的数据不一致 而http返回的数据是与服务的数据同步的

@AlexV525 AlexV525 reopened this Nov 27, 2024
@AlexV525
Copy link
Member

提供下最小复现示例,包含同时使用 dio 和 http 的对比。

@AlexV525 AlexV525 added h: need more info Further information is requested p: dio Targeting `dio` package s: bug Something isn't working platform: web and removed i: out of support labels Nov 27, 2024
@jiajialaixi
Copy link
Author

jiajialaixi commented Nov 27, 2024

dio: ^5.7.0 http: ^1.2.2

import 'package:dio/dio.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String ip =
      "https://test-sd-wetland-api.sdccx.cn:58801/wetland/commonarticle/listPage?pageNum=1&pageSize=20&articleType=4";
  String authorization =
      "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxODQ4MTY5MTcwODYxMTYyNDk2LCJ1c2VyX2tleSI6IjVjM2VkZGM5LTVjYmUtNGRkMy05YjlmLTc3OGFkMjZiZWU3MyIsInVzZXJuYW1lIjoiY2h4aHkifQ.Niq9x9nybPBdiomm0XraT0L_l6vj5VfYLMbb7lBqxQnOl88DEAVtHcUYcQs7vuxdMnEP3cn772U2MCPaiFVsXA";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
                onPressed: () async {
                  final dio = Dio();
                  dio.interceptors.add(
                    InterceptorsWrapper(
                      onRequest: (RequestOptions options, RequestInterceptorHandler handler) {
                        return handler.next(options);
                      },
                      onResponse: (Response response, ResponseInterceptorHandler handler) {
                        return handler.next(response);
                      },
                      onError: (DioException error, ErrorInterceptorHandler handler) {
                        return handler.next(error);
                      },
                    ),
                  );
                  var response = await dio.get(ip,
                      options:
                          Options(contentType: Headers.jsonContentType, headers: {'Authorization': authorization}));

                  print(response);
                },
                child: const Text("dio")),
            ElevatedButton(
                onPressed: () async {
                  final url = Uri.parse(ip);
                  final headers = {'Content-Type': 'application/json', 'Authorization': authorization};

                  try {
                    final response = await http.get(url, headers: headers);
                    if (response.statusCode == 200) {
                      print(response.body);
                    } else {
                      print('Request failed with status: ${response.statusCode}');
                    }
                  } catch (e) {
                    print('Error: $e');
                  }
                },
                child: const Text("http"))
          ],
        ),
      ),
    );
  }
}

@jiajialaixi
Copy link
Author

image
这个是dio返回数据的第一条id
image
这个是http返回数据的第一条id

实际上dio断点显示的数据是与response返回的数据不一致的

@AlexV525
Copy link
Member

Token 已过期

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
h: need more info Further information is requested p: dio Targeting `dio` package platform: web s: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants