IdHTTP.get returns HTTP1.1 / 403 Forbidden

I am trying to access the update.txt file on my website using the compiled DelphiXE program and the IdHTTP component.

The code I use is as follows:

procedure TFormAbout.SpeedButtonUpdateClick(Sender: TObject); function CheckUpdates: String; var lIdHttp: TIdHTTP; begin lIdHttp := TIdHTTP.Create(nil); result := lIdHttp.Get('http://www.test.com/test_down_load/update.txt'); end; var sWebVersion: String; sVersionList: TStringList; begin try sWebVersion := Checkupdates; except on E: Exception do begin ShowMEssage(E.ErrorMessage); MessageDlg('An Error occured checking for an update.',mtError,[mbOK],0); end; end; if sWebVersion <> '' then begin sVersionList.CommaText := sWebVersion; ShowMessage('Version: ' + sVersionList[0] + ' - ' + 'Date: ' + sVersionList[1]); end; end; 

This results in an error: HTTP1.1 / 403 Forbidden

The IdHTTP component is configured with the following properties.

 HandleRedirects := true; HTTPOptions [hoForceEncodeParams]; ProtocolVersion := pv1_1; Request.UserAgent := Mozilla/5.0 (compatible; Test) 

If I enter the URL in IE browser, it returns the file without errors, but when I access my program, I get an error. Any pointers would be appreciated. .htaccess is correct for the site. The rights to the file are indicated on the website: 0644.

Do I need to set any other properties for the IdHTTP component. I have only this component in the form. I need something else.

The updateinfo.txt file simply contains the text in quotation marks: "18.3.5,2011 / 12/17"

I just used "test" here instead of my actual name and program url.

Relations Adrian

+4
delphi indy10
source share
3 answers

403 means that you do not have permission to access the requested URL. The server probably needs to provide a username / password, especially if you use a .htaccess file. To do this, use the Request.UserName and Request.Password . As for why the browser doesn't ask for username / password, I assume the browser caches them from earlier access.

By the way, your SpeedButtonUpdateClick() has a memory leak. You create a new TIdHTTP object, but do not release it.

+6
source

I am facing the same problem when using the Indy Get () function.

It is more than likely that you are getting this error because you did not set the UserAgent property and the website, knowing that you are not accessing the file, as the browser makes noise.

 function CheckUpdates: String; var lIdHttp: TIdHTTP; begin lIdHttp := TIdHTTP.Create(nil); //avoid getting '403 Forbidden' by setting UserAgent lIdHttp.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'; result := lIdHttp.Get('http://www.test.com/test_down_load/update.txt'); end; 

A similar question, but the correct answer was recorded here: fooobar.com/questions/866288 / ...

+6
source

The answers did not help me until I put them together.

 //add Request.Username and supply the correct mysql username tidHttpObject.Request.Username := 'username'; //do the same for the password tidHttpObject.Request.Password := 'password'; //then add a UserAgent property with the string below tidHttpObject.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'; //finally call the get() url method of the tidHttp object Result := tidHttpObject.Get(url); 
-one
source

All Articles