What to do with "302 Found" exceptions when booting with Indy?

I am trying to upload a file to a line:

function FetchUrl(const url: string): string; var idhttp : TIdHTTP; begin idhttp := TIdHTTP.Create(nil); try Result := idhttp.Get(url); finally idhttp.Free; end; end; 

What is wrong with this code? I get an exception: HTTP / 1.1 302 Found

+4
source share
2 answers

Set the TIdHTTP.HandleRedirects property to True. Default is False.

 function FetchUrl(const url: string): string; var idhttp : TIdHTTP; begin idhttp := TIdHTTP.Create(nil); try idhttp.HandleRedirects := True; Result := idhttp.Get(url); finally idhttp.Free; end; end; 
+9
source

An HTTP 302 response code means that the remote server wants to redirect you to another URL that is listed in the Location header of the response. You need to do something special to look at the Location heading and navigate to this URL. Your http library may be able to do this automatically, so check the documentation.

+2
source

Source: https://habr.com/ru/post/1387217/


All Articles