Solved

CGI Reading the Info from a POST Action

Posted on 1998-03-26
5
141 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now