Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting Specific Header value from Head call response in Flutter

I am performing Head call as below using http:

Future<void> fetchModifiedDate(String fileUrl,BuildContext context) async{
  if (await checkNetworkConnection(context)) {
  var responseValue = [];
  var response = http.head(Uri.parse(fileUrl));
  response.then((value) {
    responseValue = value.headers.values.toString().split(",");
    modifiedDate = responseValue[1].trim();
    print(value.headers.toString());
    print(value.headers.values.toString());
  });
}

The values which I am getting from Header is as below :

  1. For print(value.hedaers.toString()),

{x-served-by: psm100.akshar-dev.ml, connection: keep-alive, last-modified: Thu, 13 Oct 2022 00:09:35 GMT, accept-ranges: bytes, date: Wed, 02 Nov 2022 10:24:35 GMT, content-length: 69910, etag: "6347573f-11116", content-type: application/json, server: openresty}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. For print(value.headers.values.toString()),

(psm100.akshar-dev.ml, keep-alive, Thu, 13 Oct 2022 00:09:35 GMT, …, application/json, openresty)

I want specific header value i.e. The value for last-modified key.
How can I get it?

>Solution :

Try the following code

value.hedaers['last-modified']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading