SOLVED Download a file from a redirection web server with TFPHTTPClient lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Segator · 2018-11-10 16:36 Hi developers, i extract some code from the online package manager to make a simple general downloader using TFPHTTPClient, the program work ok when the URL is static or directly to the file but when the server redirect i can not download the file, i attech the example here, how i can deal with the server redirections?. ---------------------------------------------------------------------- Thaddy · 2018-11-10 17:42 TFpHttpClient.AllowRedirects := true; ---------------------------------------------------------------------- Leledumbo · 2018-11-10 23:22 Be careful, some servers implement redirects that violate the standard. fphttpclient only changes method to GET if the server returns 303, otherwise the original method is preserved for the redirected request. This might cause unexpected behavior if the server expects GET but returning 301/302 (technically changing to GET is valid for these two, but it's optional so fphttpclient doesn't do so) /307/308. ---------------------------------------------------------------------- Segator · 2018-11-10 23:41 Quote from: Thaddy on November 10, 2018, 06:42:38 pmTFpHttpClient.AllowRedirects := true; Hi Thaddy thanks to response, its so simpe? Quote from: Leledumbo on November 11, 2018, 12:22:42 amBe careful, some servers implement redirects that violate the standard. fphttpclient only changes method to GET if the server returns 303, otherwise the original method is preserved for the redirected request. This might cause unexpected behavior if the server expects GET but returning 301/302 (technically changing to GET is valid for these two, but it's optional so fphttpclient doesn't do so) /307/308. but i can force the GET method for 301,302,307 and 308? how i can force to accept bad redirect standard? ---------------------------------------------------------------------- lucamar · 2018-11-10 23:56 Quote from: Segator on November 11, 2018, 12:41:39 ambut i can force the GET method for 301,302,307 and 308? how i can force to accept bad redirect standard? Basically intercepting the redirection yourself: set AllowRedirects to False and examine ResponseStatusCode for a 30x response. Do note that this is mostly useful when your initial request is a POST; if it's a GET you can simply set AllowRedirects to True and let the TFPHTTPClient deal with it, as Thaddy said. ---------------------------------------------------------------------- Leledumbo · 2018-11-10 23:57 Quote from: Segator on November 11, 2018, 12:41:39 ambut i can force the GET method for 301,302,307 and 308? how i can force to accept bad redirect standard? Technically yes, by overriding RedirectForcesGET method, which currently only checks for 303, to accept the other 30X. But you better consult the server response first. ---------------------------------------------------------------------- Segator · 2018-11-13 23:46 Thanks for help to solve it, In Lazarus/Free Pascal Trunk the redirection function check for 30x.