HTTP.Request.CustomHeaders.AddValue('Accept','application/octet-stream');
Adding
HTTP.Request.Accept: = EmptyStr;
solved my problem.
Why are you using the
Request.CustomHeaders property to set the
Accept header at all? You should be setting the
Request.Accept property to the desired value, eg:
HTTP.Request.Accept: = 'application/octet-stream';
In any case, you are leaking your
SSL object, and you will leak your
MS and
HTTP objects as well if
TIdHTTP.Get() raises an exception.
I would use this code instead:
HTTP := TIdHTTP.Create;
try
SSL := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
SSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
HTTP.IOHandler := SSL;
HTTP.HandleRedirects := True;
HTTP.ConnectTimeout := 5000;
HTTP.ReadTimeout := 5000;
HTTP.ProtocolVersion := pv1_0;
HTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1';
HTTP.Request.Accept := 'application/octet-stream';
HTTP.Request.BasicAuthentication := False;
HTTP.Request.CustomHeaders.AddValue('Authorization', 'token mytoken');
MS := TMemoryStream.Create;
try
HTTP.Get('https://api.github.com/repos/myowner/myrepo/releases/assets/123', MS);
MS.SaveToFile(SaveFile);
finally
MS.Free;
end;
finally
HTTP.Free;
end;