gpt4 book ai didi

http - 迪欧 : HttpException: More than one value for header set-cookie

转载 作者:IT王子 更新时间:2023-10-29 07:08:39 25 4
gpt4 key购买 nike

我目前正在尝试使用 Dio 从 GET 或 POST 请求中检索多个 Set-Cookie 字段。我无法使用 HttpClient 或 flutter 的 http 做到这一点。

使用 Dio 抛出异常:

HttpException: More than one value for header set-cookie

我想知道如何解决这个问题并处理多个 set-cookie header ,然后将它们发送回 cookie header 。

如何使用 Dart/Flutter 处理多个 Set-Cookie header 并将它们作为 cookie header 发回?

这是MCVE

Dio dio = new Dio();

dio.get(urlLogin).then((Response resp){
print('-----Login-----');
print(resp.headers.value('set-cookie'));
});

还有 StackTrace

HttpException: More than one value for header set-cookie
#0 _HttpHeaders.value (dart:_http/http_headers.dart:48:7)
#1 loginDio.<anonymous closure> (file:///home/fuguet/Prog/Dart/FPlogin/main.dart:55:24)
#2 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#3 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#5 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#6 Future._complete (dart:async/future_impl.dart:476:7)
#7 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#8 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#11 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#12 Future._complete (dart:async/future_impl.dart:476:7)
#13 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#14 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#15 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#16 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#17 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#18 Future._completeWithValue (dart:async/future_impl.dart:486:5)
#19 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:516:7)
#20 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#22 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:391:30)
#23 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#24 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

最佳答案

因为可能有多个 header 同名,所以不能使用 value() .而是使用 []检索 List<String> .

List<String> rawCookies = resp.headers['set-cookie'];

关于http - 迪欧 : HttpException: More than one value for header set-cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52645031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com