Search code examples
androiddelphiindydelphi-xe6

Delphi XE6 post request and indy


I have a Delphi XE6 application which I would like to install on an Android phone. I am testing it on a Windows platform. Below is my unit source code. On my form I have a button, idHttp Indy tool and a Memo Field.

The problem is that when I click the button I get the error

HTTP/1.1 403 Forbidden.

But I can access the site through my browser, so the page isn't forbidden. Can anyone see a problem?

I have searched for how to do post requests using firemonkey and delphi and I found these links:

None of which help me.

unit Start_Interface_u;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  FMX.Layouts, FMX.Memo;

type
  TForm1 = class(TForm)
    btnLogin: TButton;
    IdHTTP1: TIdHTTP;
    Memo1: TMemo;
    procedure btnLoginClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

  {$R *.fmx}


  procedure TForm1.btnLoginClick(Sender: TObject);
  Var
    sResult: String;
    DataToSend :TStringList;
  begin

  DataToSend := TStringList.Create;
  //DataToSend.Add('login_email=some_email');
  //DataToSend.Add('login_pass=some_password');
  IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';

  Memo1.Lines.Add(idHTTP1.Post('http://mysite.co.za/dash.php', DataToSend));

  end;

end.

Solution

  • I would try to set the user agent to simulate a common web browser, for example (taken from this answer)

    Request.UserAgent := 
          'Mozilla/5.0 (Windows NT 5.1; rv:2.0b8) Gecko/20100101 Firefox/4.0b8';