Dart: HttpException: Failed to parse header value
我得到一个
HttpException: Failed to parse header value
使用 M2 发行版 dart http 和 oauth2 库调用 http.Client.get(Uri) 方法时。我正在尝试使用 API 来执行 File: get.我成功地将我的授权请求重定向到一个简单的基于控制台的 http 服务器以获取令牌。然后以下代码会导致异常:
1 2 3 4 | oauth.Credentials credentials = new oauth.Credentials(code); http.Client client = new oauth.Client(CLIENT_ID, CLIENT_SECRET, credentials); Uri uri = new Uri("https://www.googleapis.com/drive/v2/files/$fileID"); Future<http.Response> result = client.get(uri); |
以下是完整的堆栈跟踪:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | HttpException: Failed to parse header value Unhandled exception: FutureUnhandledException: exception while executing Future HttpException: Failed to parse header value original stack trace: null #0 _FutureImpl._complete (bootstrap:844:11) #1 _FutureImpl._complete (bootstrap:848:5) #2 _FutureImpl._setException (bootstrap:873:14) #3 _CompleterImpl.completeException (bootstrap:952:30) #4 _FutureImpl._forwardException. (bootstrap:936:34) #5 _FutureImpl._complete (bootstrap:832:22) #6 _FutureImpl._complete (bootstrap:848:5) #7 _FutureImpl._setException (bootstrap:873:14) #8 _CompleterImpl.completeException (bootstrap:952:30) #9 _FutureImpl._forwardException. (bootstrap:936:34) #10 _FutureImpl._complete (bootstrap:832:22) #11 _FutureImpl._complete (bootstrap:848:5) #12 _FutureImpl._setException (bootstrap:873:14) #13 _CompleterImpl.completeException (bootstrap:952:30) #14 _FutureImpl._forwardException. (bootstrap:936:34) #15 _FutureImpl._complete (bootstrap:832:22) #16 _FutureImpl._complete (bootstrap:848:5) #17 _FutureImpl._setException (bootstrap:873:14) #18 _CompleterImpl.completeException (bootstrap:952:30) #19 _FutureImpl._forwardException. (bootstrap:936:34) #20 _FutureImpl._complete (bootstrap:832:22) #21 _FutureImpl._complete (bootstrap:848:5) #22 _FutureImpl._setException (bootstrap:873:14) #23 _CompleterImpl.completeException (bootstrap:952:30) #24 IOClient.send.. (package:http/src/io_client.dart:38:36) #25 _FutureImpl._complete (bootstrap:840:19) #26 _FutureImpl._complete (bootstrap:848:5) #27 _FutureImpl._setValue (bootstrap:862:14) #28 _CompleterImpl.complete (bootstrap:949:26) #29 async. (package:http/src/utils.dart:173:41) #30 _Timer._createTimerHandler._handleTimeout (dart:io:7035:28) #31 _Timer._createTimerHandler._handleTimeout (dart:io:7043:7) #32 _Timer._createTimerHandler. (dart:io:7051:23) #33 _ReceivePortImpl._handleMessage (dart:isolate-patch:37:92) |
要使用 Google Drive SDK API,您可以使用适用于 Dart 的 Google APIs 客户端库,它允许从 Dart 应用程序访问 Google API。
https://github.com/Scarygami/dart-google-oauth2-library 是基于此构建的,它可以作为替代方案。
你可能还没有初始化 SSL?
1 | SecureSocket.initialize(); |
有关详细信息,请参阅 http://api.dartlang.org/docs/bleeding_edge/dart_io/SecureSocket.html。