Thanks molly, I'm starting to think that I'm on a rock-climb and have reached an 'Overhang'
Running your 'nasa_getmem' program, it compiles without an error regarding 'ResponseStatusCode' but using the same statement in my program tells me 'Identifier not found'. I can't see anywhere in nasa_getmem where it is declared and I've checked that I have Classes, SysUtils & fphttpclient in the [uses] clause so can't work out where you have declared it.
Notwithstanding that, I then tried to force an exception in nasa_getmem by changing the filename to an obviously non-existent one (just added 'A_' to the start) but stepping through, it never got to line 26 'on E: Exeption ... ' - - - at line 24 it threw a 404 Status Code.
In all probability I'm being a 'Numpty' but would appreciate guidance.
Going back to my code; I think I know why I'm receiving a 400 Status Code - even though it is inconsistent and imponderable.
I create the arguments for Get() from the URL, local-Directory & filename for each file I want to download using global string variables U and F which ultimately become URL and Filename in the Download2File function. Stepping through and watching U, F, URL and Filename I'm seeing that sometimes URL is an empty string rather than what U is. ????? How can that be?
Further, as a test, I changed the call from Get(URL,Filename) to Get(U,F) but still got a 400 Status Code.
As you know, I have 6 sub-directories for each 'Concert', and currently have three concerts. One concert (Disney) all files download to all directories perfectly but 'Christmas' fails on one directory after the first 1 or 2 - even that is inconsistent! The only thing that changes between each call to Download2File is the filename - the directory and URL are consistent, with the filename being added immediately prior to the call. Putting 'Disney' files into 'Christmas' they download correctly so I've even re-created the 'rogue' files but still get a failure.
In case it helps, here is the latest version of the Download2File function :
function Download2File(URL: String; Filename: String): boolean;
Var
SC : byte;
begin
Result := false;
with TFPHttpClient.Create(Nil) do
try
AllowRedirect := true;
Get(U,F);
// Get(URL, FileName);
Result := true;
except
end;
if ResponseStatusCode = 200 then
begin
//success, do other things if needed
Result := True;
end
else
begin
SC := ResponseStatusCode Div 100;
case SC of
1 : begin
end;
2 : begin
end;
3 : begin
end;
4 : begin
showmessage('Copy of '+F+' Failed with Code'+ResponseStatusCode);
end;
5 : begin
end;
end;
end;
finally
Free;
end;
end;
... preparing for the Status Code test.
I feel that there should be something else between lines 12 & 13 but can't suggest what.
and the procedure that creates U & F is:
procedure TForm1.DL_CAPClick(Sender: TObject);
Var
i : byte;
Fl : string;
begin
DL_Label.Show;
DL_Progress.Show;
application.ProcessMessages;
For i := 0 to pred(C_Count) do
begin
Fl := C_List[i] + '.CAP';
U := CAP_URL + Fl;
F := MusDir + URL_List[6] + Fl;
if Download2File(U,F) = false then
begin
showmessage('Download of '+F+' failed');
end;
DL_Progress.Position := trunc((succ(i)/C_Count)*100);
application.ProcessMessages;
end;
Sleep(5000);
DL_Label.Hide;
DL_Progress.Hide;
DL_CAP.Enabled:=false;
end;
One of the filenames that fails is 'Hark! The Herald.cap' and yes, I
have tried without the exclamation mark. (Clutching at straws!) Spaces are no problem in other filenames either eg. '12 days AFTER Christmas.cap' doesn't fail. Thinking that file size might be the issue I've checked that, and 'Hark' is 16Kb but others (which don't fail) exceed 7Mb.