如何获得响应的授权标题?

时间:2016-07-30 01:37:31

标签: dart

我使用以下代码将Protected Sub HandLine1Size_SelectedIndexChanged(sender As Object, e As EventArgs) Handles HandLine1Size.SelectedIndexChanged Select Case HandLine1Size.SelectedValue Case "1" Line1Co.Value = "12" Case "1.5625" Line1Co.Value = "8" Case "2.25" Line1Co.Value = "2" Case "3.0625" Line1Co.Value = "0.75" Case Else Line1Co.Value = "20" End Select End Sub 发布到服务器的登录路径:

formdata

服务器响应标头是:

  

授权:ShelfAuthJwtSession eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0Njk4NDEzNjQsImV4cCI6MTQ2OTg0MzE2NCwiaXNzIjoiY2xvdWRfc2NhbGVfc3lzdGVtIiwic3ViIjoiQ0xPVUQtU0MtVkVORE9SIiwiYXVkIjpbbnVsbF0sInNpZCI6IjJmNGUxOGMwLTRjMzAtMTFlNi1hMmExLWFmMjY5MDNiNTBjOCIsInRzZSI6MTQ2OTkyNzc2NH0.OoEuYlsItdwjciyZxDTcMi29JSUyZcrZ_2EApkTA12c   内容类型:文本/无格式;字符集= utf-8的   日期:2016年7月30日星期六01:16:04 GMT   服务器:dart:io with Shelf   传输编码:分块   X-内容类型选项:nosniff   X框选项:SAMEORIGIN   X-XSS-保护:1;模式= block`

但它只打印var data = {"username": username, 'password' : password}; HttpRequest.postFormData(Service.serverUrl + "/login", data).then((response) { if (response.status == 200) { response.responseHeaders.forEach((key, value){ print(key); print(value); }); }});` 标题 - 其他标题不包括在内。那是为什么?

1 个答案:

答案 0 :(得分:0)

我有一个用于http请求的小型帮助程序包。它包含一个httpUtils类,该类可以返回包含标头的完整响应对象。在Flutter上也可以正常工作!

Github:https://github.com/Ephenodrom/Dart-Basic-Utils

安装:

dependencies:
  basic_utils: ^1.3.0

用法:

Response response = await HttpUtils.postForFullResponse(Service.serverUrl + "/login", data);
String authData = response.headers["authorization"];

此软件包中包含的所有其他http方法:

Future<Map<Response> getForFullResponse(String url,{Map<String, dynamic> queryParameters,Map<String, String> headers});
Future<Map<String, dynamic>> getForJson(String url,{Map<String, dynamic> queryParameters,Map<String, String> headers});
Future<String> getForString(String url,{Map<String, dynamic> queryParameters,Map<String, String> headers});
Future<Map<Response> postForFullResponse(String url, String body,{Map<String, String> queryParameters,Map<String, String> headers});
Future<Map<String, dynamic>> postForJson(String url, String body,{Map<String, String> queryParameters,Map<String, String> headers});
Future<String> postForString(String url, String body,{Map<String, String> queryParameters,Map<String, String> headers});
Future<Response> putForFullResponse(String url, String body,{Map<String, String> queryParameters,Map<String, String> headers});
Future<Map<String, dynamic>> putForJson(String url, String body,{Map<String, String> queryParameters,Map<String, String> headers});
Future<String> putForString(String url, String body,{Map<String, String> queryParameters,Map<String, String> headers});
Future<Response deleteForFullResponse(String url,{Map<String, String> queryParameters,Map<String, String> headers});
Future<Map<String, dynamic>> deleteForJson(String url,{Map<String, String> queryParameters,Map<String, String> headers});
Future<String> deleteForString(String url,{Map<String, String> queryParameters,Map<String, String> headers});
Map<String, dynamic> getQueryParameterFromUrl(String url);
String addQueryParameterToUrl(String url, Map<String, dynamic> queryParameters);