UPDATED
I need help extracting the Date from my response headers in a POST request. Currently, I'm only able to retrieve the Content-Type header. Is there a way to access the date information as well?
After making a POST request, these are the response headers:
https://i.sstatic.net/YFH75.png
Below is the utility function I am using for sending the POST request:
export default async function postData(url, func, audience, requestObj) {
const accessToken = await func({
audience: audience,
});
const myHeaders = new Headers();
myHeaders.append('authorization', `Bearer ${accessToken}`);
myHeaders.append('Content-Type', 'application/json');
const raw = JSON.stringify(requestObj);
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow',
};
const response = await fetch(url, requestOptions);
const transactionDate = response.headers.get('Date');
//This returns null
console.log('Date', transactionDate);
//This returns only the Content-Type
for (let pair of response.headers.entries()) {
console.log(pair[0] + ': ' + pair[1]);
}
if (!response.ok) {
if (response.status >= 500 && response.status <= 599) {
throw new Error(
'A server error occurred and we were unable to submit your data.'
);
} else if (response.status >= 400 && response.status <= 499) {
const text = await response.text();
throw new Error(text);
} else {
throw new Error(`${response.status}: ${response.statusText}`);
}
}
const result = await response.json();
return result;
}