Delphi - 'Invalid argument to date encode', because Value['Expires']=-1
delphi, http-headers, indy
Solution
As described here, Indy versions < 10 don't process "-1" correctly. This is how Indy 10 handles the "Expires" field:
// RLebeau 01/23/2006 - IIS fix
lValue := Values['Expires']; {do not localize}
if IsNumeric(lValue) then
begin
// This is happening when expires is an integer number in seconds
LSecs := Sys.StrToInt(lValue);
// RLebeau 01/23/2005 - IIS sometimes sends an 'Expires: -1' header
if LSecs >= 0 then begin
FExpires := Sys.Now + (LSecs / SecsPerDay);
end else begin
FExpires := 0.0;
end;
end else
begin
FExpires := GMTToLocalDateTime(lValue);
end;
As you can see, the value is set to 0 if it was <= 0 initially, so this is what you have to do manually if you're using an older version of Indy.
Problem
I've been working with a application using delphi where the application needs to connect with a url like a "example.example.ex". When I call the function `IdHTTP1.Post`, an error occurs in the date enconding process. What happens is that, when the application get some values of connection header, the "Expires" is -1, and the function `function RawStrInternetToDateTime(var Value: string): TDateTime;` that internally uses `EncodeDate(Year, Month, Day);` can't work with the value '-1'. Will I need to change directly on "exemple.exemple.ex", the "expires" value to some other datetime value?