-2

I use an HTTP component in Borland Delphi 3.0 (old version Delphi). No Indy TIdHTTP component available yet. Just using HTTP components.

I use POST and GET to process a form of registration for my program application (Radio Calculator v3.50). My program

The plan is here.

POST form:

Include Username, Email, Phone number, and JPG file (transfer to my account) --> there are 4 parameters.

First, I use POST for "processing" the different KEYs for every different Username. This is processed in my Web Server using PHP and Microsoft Access MDB as the database.

I use another HTTP process from Delphi (GET), a few minutes later (let's says 15 minutes), to get a Username and KEY of the registration person in their home, or wherever they are around the world.

They will get DATA automatically from my Web Server using PHP.

My questions:

  1. How can I use POST and GET commands in HTTP Delphi Components? With all 4 parameters I use simple coding here from a similar post:

    function PostExample: string; 
    var 
      lHTTP: TIdHTTP; 
      lParamList: TStringList; 
    begin 
      lParamList := TStringList.Create;
      lParamList.Add('id=1'); 
      lHTTP := TIdHTTP.Create; 
    
      try 
        Result := lHTTP.Post('http://blahblahblah...', lParamList); 
      finally 
        lHTTP.Free; 
        lParamList.Free; 
      end; 
    end;
    

    How can I process the POST and GET result? What variables will be filled with this syntax? And how can I use this for further processing?

  2. Will this procedure work fine, or is there some leakage in securities in it?

  3. I use POST HTTP, sending these parameters, process it using PHP in my Web Server, and I get the raw result using GET a few minutes later. Is there anything I missed in the procedure? Should GET be instantly requested after POST, or how should I do it? Should I change HTTP to TWebBrowser only? Just make a Web Browser in Delphi? So I don't have to think hard about the HTTP process, only use my PHP programming competency instead?

How coding uses TIdHTTP.Post() to PHP:

procedure TForm1.Button1Click(Sender: TObject);
Var
  params : TStringList;
  res : TStringStream;
begin
  params := TStringList.Create;
  params.Add('a='+'hello');
  res := TStringStream.Create('');
  idhttp1.Post('http://localhost/test/hallo.php', params, res);
  ShowMessage(res.DataString);
  res.Free;
  params.Free;
end;
<?php
echo $_POST['a'];
%>

i ve UPLOAD IT IN GITHUB NGAB. Here 100% Works

21
  • I don't understand what you are asking for. Please clarify. Also, are you really using Delphi 3, ie a 26 year old compiler? Mar 23 at 18:42
  • Right. i use Delphi V3.0 ( old version of Delphi) from my CD Collection 23 years ago.
    – adhitronic
    Mar 23 at 18:56
  • i m asking about the RESULT parameter. what variables are "filled" with this parameter. if the result is true.
    – adhitronic
    Mar 23 at 18:58
  • Indy does not officially support Delphi v3 (IIRC, v5 is the oldest version still supported). The Result in your example is just a string, it will receive whatever raw text the server decides to send back to you (ie, HTML, JSON, XML, etc). There are no "parameters" in that Result from Indy's perspective. You will have to parse that string yourself to extract whatever data you need from it. Mar 23 at 19:02
  • raw data what this like JSON ? Where i can find this raw data ? which variable? yes i m not using Indy HTTP. I only use HTTP Components. I was learning Delphi since 1995 and i a little bit forget about the syntaxs here.
    – adhitronic
    Mar 23 at 19:06

1 Answer 1

0

Delphi 3 predates Indy by quite a few years. Before Indy, Delphi shipped with a VCL component suite known as FastNet (later NetMasters), but I don't know if they go all the way back to Delphi 3 or not. Before FastNet, Delphi shipped with a suite of ActiveX controls from NetManage.

If you are using NetManage's HTTP ActiveX control, then I can't help you. I have no information on that control at all.

If you are using FastNet/NetMasters TNMHTTP component, then the Indy code you have shown would probably translate into something like the following for TNMHTTP (the FastNet/NetMaster components have been dead for a very long time, and there is no surviving documentation for them, so I'm basing this solely on looking at the NMHTTP.hpp C++ header file shipped in C++Builder v5, since no FastNet/NetMasters source code was provided with Delphi/BCB, or that I have access to, anyway):

procedure TForm1.Button1Click(Sender: TObject);
begin
  NMHTTP1.Post('http://localhost/test/hallo.php', 'a=hello');
end;

// NHTTP1.OnSuccess event handler
procedure TForm1.NMHTTP1Success(Cmd: CmdType);
begin
  ShowMessage('Success: ' + NMHTTP1.Body);
end;

// NHTTP1.OnFailure event handler
procedure TForm1.NMHTTP1Failure(Cmd: CmdType);
begin
  ShowMessage('Failed');
end;

Alternatively:

type
  TMyNMHTTP = class(TNMHTTP)
  public
    constructor Create(AOwner: TComponent); override;
    procedure HTTPSuccess(Cmd: CmdType);
    procedure HTTPFailure(Cmd: CmdType);
  end;

constructor TMyNMHTTP.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  OnSuccess := HTTPSuccess;
  OnFailure := HTTPFailure;
end;

procedure TMyNMHTTP.HTTPSuccess(Cmd: CmdType);
begin
  Tag := 1;
end;

procedure TMyNMHTTP.HTTPFailure(Cmd: CmdType);
begin
  Tag := 2;
end;

function PostExample: string; 
var 
  lHTTP: TMyNMHTTP;
begin 
  Result := '';
  lHTTP := TMyNMHTTP.Create(nil);
  try 
    lEvents.Tag := 0;
    lHTTP.Post('http://blahblahblah...', 'id=1');
    repeat
      Application.ProcessMessages;
    until lHTTP.Tag <> 0;
    if lHTTP.Tag = 1 then
      Result := lHTTP.Body;
  finally 
    lHTTP.Free; 
  end; 
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Response: string;
begin
  Response := PostExample();
  if Response <> '' then
    ShowMessage('Success: ' + Response)
  else
    ShowMessage('Failed');
end;
5
  • i m decide to install Delphi 6.0. Theres an Indy HTTP Components. looks like same component i use in Delphi 3.0. i use picture above. the link i give to you. will php works fine in these sample ?
    – adhitronic
    Mar 24 at 3:46
  • Thank for your answer using C++ Builder coding.
    – adhitronic
    Mar 24 at 3:47
  • PHP says it echo $_POST['a']; looks like i m goin to process the a variable to make a KEY for those 'Username a'. lets says usin XOR or AND function in php. and save it to .mdb Database also sends it back to Client Delphi using TidHttp component. Will my online registerin works ngab ?
    – adhitronic
    Mar 24 at 3:55
  • So whats the GET method function. is usin this will make the program get infos KEY assoaiates with Username
    – adhitronic
    Mar 24 at 3:57
  • 3
    You are asking too many questions and dragging out this conversion. That is a Q&A site, not a discussion forum. Ask a question, get an answer, move on. Further questions should be asked in separate posts. Mar 24 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.