https://www.pdfdrive.com/
now please help
As I expected, the \download.pdf URL you have given, results in a 301 code, which is a redirection.
If you folow that redirection (with Allowredirect := true) it still gives a 400 error code (Bad Request).
There is still something that the server expects and is not given.
Cookies should be saved between the redirection.
I also tried a different User-agent, but that also didn't work.
Will try later on.
Code for now:
uses fphttpclient, opensslsockets;
procedure TForm1.Button1Click(Sender: TObject);
var
HTTP: TFPHttpClient;
Stream: TMemoryStream;
URL: string;
begin
HTTP := TFPHttpClient.Create(nil);
Stream := TMemoryStream.Create;
try
HTTP.AllowRedirect := true;
HTTP.AddHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36');
URL := 'https://www.pdfdrive.com/download.pdf?id=10172273&h=84f0f3490acb0a861ce0cf97be914eed&u=cache&ext=pdf';
try
HTTP.HTTPMethod('GET', URL, Stream, [200, 301, 400]); // 400 shouldn't happen !
Stream.SaveToFile('c:\temp\test.pdf');
// HTTP.Get(URL, 'c:\temp\test.pdf'); // gives a 301 exception
Memo1.Lines.Add(HTTP.ResponseHeaders.Text);
except
on E: Exception do
Memo1.Lines.Add(HTTP.ResponseHeaders.Text);
end;
finally
HTTP.Free;
Stream.Free;
end;
end;
wget on linux works fine on the link so it should be too difficult.