Solved

CGI Reading the Info from a POST Action

Posted on 1998-03-26
5
146 Views
Last Modified: 2010-04-06
I have created a CGI class but I need to decode the fields sent to me when I use a POST action. How do I do that ???

This one is urgent so I pay a lot for it.
0
Comment
Question by:malaland
  • 4
5 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 300 total points
ID: 1360944
Hi malaland,

Here are some functions to accomplish the task. Tey were extracted from FPiettes CGI sample.

All you have to use is the GetValue procedure, the others are auxiliar. An example goes below.

The functions:

function isxdigit(Ch: char) : Boolean; forward;
function xdigit(Ch: char) : Integer; forward;
function htoin(value: PChar; len: Integer) : Integer; forward;
function GetValue(Msg: String; Name: String; var Val: String): Boolean; forward;

function isxdigit(Ch : char) : Boolean;
begin
    Result := (ch in ['0'..'9']) or (ch in ['a'..'z']) or (ch in ['A'..'Z']);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function xdigit(Ch : char) : Integer;
begin
    if ch in ['0'..'9'] then
        Result := ord(Ch) - ord('0')
    else
        Result := (ord(Ch) and 15) + 9;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function htoin(value : PChar; len : Integer) : Integer;
var
    i : Integer;
begin
    Result := 0;
    i      := 0;
    while (i < len) and (Value[i] = ' ') do
        i := i + 1;
    while (i < len) and (isxDigit(Value[i])) do begin
        Result := Result * 16 + xdigit(Value[i]);
        i := i + 1;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function GetValue(Msg: String; Name: String; var Val: String): Boolean;
var
    I       : Integer;
    NameLen : Integer;
    Ch      : Char;
begin
    Val     := '';
    NameLen := Length(Name);

    I := Pos(Name, Msg);
    if I = 0 then begin
        Result := FALSE;
        Exit;
    end;

    I := I + NameLen;
    while (Msg[I] <> #0) and (Msg[I] <> '&') do begin
        Ch := Msg[I];
        if Ch = '%' then begin
            Ch := chr(htoin(@Msg[I + 1], 2));
            I  := I + 2;
        end
        else if Ch = '+' then
            Ch := ' ';

        Val := Val + Ch;
        Inc(I);
    end;
    Result := TRUE;
end;

The example:

procedure TForm1.Button1Click(Sender: TObject);
var token: string;
      Source: string;
begin
                  Source := 'pg=q&what=web&kl=XX&field=cora%E7%E3o&search.x=41
      GetValue(Source, 'field=', token);
                  Edit1.Text := token;
                  GetValue(Source, 'what=', token);
                  Edit2.Text := token;
end;

// Edit1 will show the result: "coração" (heart in portuguese).
// and Edit2 will show the result: "web", and so on...

I believe it will be usefull. If you need to elaborate it (and have time) I could help you.

IHTH,

Itamar

P.S.: Any doubts, place a comment before rejecting the answer.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1360945
Hi malaland,

I put this coment just to fire a msg for you, as you said it was urgent.

Bye,
Itamar
0
 
LVL 4

Expert Comment

by:itamar
ID: 1360946
Hi !

Anybody there ????
0
 

Author Comment

by:malaland
ID: 1360947
You did not quite get the answer but I found out by myself. To read the POST information comming into my CGI application, I needed to read the standard IN. Thanks for you help.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1360948
Maladand,

First of all, your question mentions "decode the fields sent to me" ! To decode something I guess you already know how to get the thing to be decoded !!!!

I sugest you to make the questions more clear, this way you'll save everybody's time and will not frustate someone with such a low grade :(((((
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question