Solved

CGI Reading the Info from a POST Action

Posted on 1998-03-26
5
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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