-1

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

adhitronic
  • 11
  • 4
  • I don't understand what you are asking for. Please clarify. Also, are you really using **Delphi 3**, ie a **26 year old** compiler? – Remy Lebeau Mar 23 '23 at 18:42
  • Right. i use Delphi V3.0 ( old version of Delphi) from my CD Collection 23 years ago. – adhitronic Mar 23 '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 '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. – Remy Lebeau Mar 23 '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 '23 at 19:06
  • The data is *whatever text* the server sends back. It *might* be JSON, it *might* be something else, that is entirely up to the server, not Indy. The data is being put into *your* `Result` variable, do whatever you want with it after `TIdHTTP.Post()`/`TIdHTTP.Get()` exits. – Remy Lebeau Mar 23 '23 at 19:07
  • in 2000 i makr a Socket program. its simple. and now i m planning to make HTTP applicationd. Like RESTFUL API nowadays. Just to applied in Registration session of my Program App i make. – adhitronic Mar 23 '23 at 19:09
  • Most REST APIs use JSON nowadays, but XML is also not uncommon. Again, that is up to the *server* to decide. – Remy Lebeau Mar 23 '23 at 19:10
  • @RemyLebeau. Only ONE Variable in named Result ? owh is JSON only one variable filled by text only ? – adhitronic Mar 23 '23 at 19:11
  • What part of "`TIdHTTP` will give you WHATEVER THE SERVER SENDS" is unclear? Do you understand what a `string` is? `TIdHTTP` will receive the raw bytes that are sent by the server, put them into a `string`, and RETURN THAT `string` TO YOU. Period. In the code you have shown, YOU are receiving that `string` into your function's `Result` variable. – Remy Lebeau Mar 23 '23 at 19:12
  • After using POST. I use GET . the Result parameter from Server.Web. it comes from calculation of my PHP Program. will the result fillrd with thIs data JSON ? In this case the KEY for each Username ? – adhitronic Mar 23 '23 at 19:14
  • If the server decides to send back a response in JSON format, then your `Result` variable will receive JSON data, yes. Use the `TIdHTTP.Response.ContentType` property to know what kind of data the server actually sent. – Remy Lebeau Mar 23 '23 at 19:17
  • yes i know STRING data. so its the raw data sends to my Delphi Client app. if more than 1 data it formed as JSON or XML. So i have to parse it into each parameter from those text ( raw data ) right ??? – adhitronic Mar 23 '23 at 19:18
  • As I said earlier: "*You will have to parse that `string` yourself to extract whatever data you need from it*", yes – Remy Lebeau Mar 23 '23 at 19:19
  • but it only raw data. Theres JSON in1998. i think its an XML format ? – adhitronic Mar 23 '23 at 19:20
  • Just run the code for yourself, look at the actual data you are really receiving, and then write your code to parse that data as needed. I've answered your original question. I'm done with this conversation, it is not going anywhere further. Good luck. – Remy Lebeau Mar 23 '23 at 19:25
  • i use POST HTTP. Using these parameter. process it using PHP in My Web Server. And i get the raw using GET a few minutes later. Is there any i missed procedures here ? Should GET instantly requested after POST or HOW Should I Do ? – adhitronic Mar 23 '23 at 19:27
  • i use PHP to process the KEY. Any other suggest ngab brothers ? See pictures in coding i m used. – adhitronic Mar 23 '23 at 22:21
  • I re-read your question, and I see that you are not actually using Indy `TIdHTTP` in Delphi 3, so that whole thing really distracted from your actual question. Which HTTP component are you *actually* using? "Delphi HTTP component" is not descriptive enough. I have posted an answer in an attempt to help you, but I'm really shooting in the dark here. Also, why are you using GET after POST, instead of having your web server send back the procssed data directly in reply to POST? Does it really take minutes for your web server to process your data? – Remy Lebeau Mar 24 '23 at 01:21
  • So its enough to use POST Method only. Doesnt need GET Method. for nowaday POST return results in Result Variable (Data KEY). Thanks before ngab. – adhitronic Mar 24 '23 at 05:44
  • I use XAMPP to make a localhost and i creates php scripts ( i used to make in Webs Programming ) like in examples above. i m learning about this POST method in Delphi ngab. By the way thank you for your Participating my Post. I appreciate it. @RemyLebeau. Thank again just for all readers and there you are ngab. – adhitronic Mar 24 '23 at 05:58

1 Answers1

1

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 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 '23 at 03:46
  • Thank for your answer using C++ Builder coding. – adhitronic Mar 24 '23 at 03: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 '23 at 03:55
  • So whats the GET method function. is usin this will make the program get infos KEY assoaiates with Username – adhitronic Mar 24 '23 at 03: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. – Remy Lebeau Mar 24 '23 at 06:05