Skip to content

http get can't solve response error : Invalid media type #19348

@DuanTzXavier

Description

@DuanTzXavier

Logs

07-14 01:59:51.068 2137-2153/top.basking.calculator I/flutter: 200
07-14 01:59:51.068 2137-2153/top.basking.calculator I/flutter: {connection: keep-alive, content-type: application/json; charset=utf-8;, transfer-encoding: chunked, date: Fri, 13 Jul 2018 17:59:15 GMT, server: nginx}
07-14 01:59:51.070 2137-2153/top.basking.calculator E/flutter: [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
                                                               Error on line 1, column 33: Invalid media type: expected /[^()<>@,;:"\\\/[\]?={} \t\x00-\x1F\x7F]+/.
                                                               application/json; charset=utf-8;
                                                                                               ^
                                                               #0      wrapFormatException (package:http_parser/src/utils.dart:15:5)
                                                               #1      new MediaType.parse (package:http_parser/src/media_type.dart:46:12)
                                                               #2      _contentTypeForHeaders (package:http/src/response.dart:93:39)
                                                               #3      _encodingForHeaders (package:http/src/response.dart:86:22)
                                                               #4      Response.body (package:http/src/response.dart:27:22)
                                                               #5      ExchangeCalculatorScreenState.loadData (package:calculator/screens/ExchangeCalculatorScreen.dart:465:20)
                                                               <asynchronous suspension>

Code

var  dataURL = "http://api.k780.com?app=finance.rate&scur=CNY&tcur=GBP&appkey=35134&sign=fb020c3129435bb5ff21b7113e9cb1c1&format=json";
    print(dataURL);
    var response = await http.get(
        dataURL);
    print(response.statusCode);
    print(response.headers);
    print(response.body);

can't resolve response.body

but when I use UTF8Codec class resolve bodybytes ,it works!

print(Utf8Codec().decode(response.bodyBytes));

here is success log:

{"success":"1","result":{"status":"ALREADY","scur":"CNY","tcur":"GBP","ratenm":"人民币/英镑","rate":"0.113045","update":"2018-07-13 23:28:01"}}

flutter doctor -v

$ flutter doctor -v
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-NZ)
    • Flutter version 0.5.1 at /Users/tzduan/development/flutter
    • Framework revision c7ea3ca377 (6 weeks ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 26.0.2)
    • Android SDK at /Users/tzduan/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 26.0.2
    • ANDROID_HOME = /Users/tzduan/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 23.2.1
    • Dart plugin version 171.4424
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)

[!] IntelliJ IDEA Ultimate Edition (version 2017.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.io/intellij-setup/#installing-the-plugins

[!] VS Code (version 1.24.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions