I'm trying to use TIdHTTP.Head('https://www.myurl.com/myfile.zip')
, just to get the file size before downloading it.
I get the file size so I can open multiple threads downloading parts of the file in parallel, so the download will be faster.
It was working OK until recently, when the Head()
method started to raise this exception:
Project myproject.exe raised exception class EIdHTTPProtocolException with message 'HTTP/1.1 406 Not Acceptable'.
My TIdHTTP
is connected to a TIdSSLIOHandlerSocketOpenSSL
, with these SSLOptions
:
Method = sslvSSLv23
SSLVersions = [sslvSSLv2,sslvSSLv3,sslvTLSv1,sslvTLSv1_1,sslvTLSv1_2]
What should I look for?
A 406 Not Acceptable
error comes from the HTTP server. It usually1 means that the request has an Accept
header specifying the type(s) of data the client is willing to receive, but the server is not able to send the requested resource in any of those types.
1 Less likely, the error could also mean an intermediate firewall is blocking the request.
The default TIdHTTP.Request.Accept
value is 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
. The */*
should include .zip
files, but if you know that you are only interested in a .zip
file and nothing else then you should set the TIdHTTP.Request.Accept
property to 'application/zip'
instead.
On a side note: you should NOT be enabling sslvSSLv2
and sslvSSLv3
in the SSLIOHandler's SSLVersions
property. They are old and deprecated, as they are no longer secure, nobody uses SSL v2.0 and v3.0 anymore.