Eric
Eric

Reputation: 75

Delphi - 'Invalid argument to date encode', because Value['Expires']=-1

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?

Upvotes: 3

Views: 8929

Answers (1)

DNR
DNR

Reputation: 1659

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.

Upvotes: 8

Related Questions