Solved

CGI Reading the Info from a POST Action

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

19 Experts available now in Live!

Get 1:1 Help Now