Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Post using Indy idHTTP

5,144 views
Skip to first unread message

Sean

unread,
Feb 20, 2001, 4:01:16 AM2/20/01
to
hi,

I am trying to post information to a webpage, as in input fields ie <INPUT
Type="text" name="dadada" value="sasad">
I am using the Indy Http component with post but it just brings back a html
reponse of "field not found etc etc".

Does anyone know how I can post to a site ???

thanks,

Doychin Bondzhev

unread,
Feb 20, 2001, 4:35:32 PM2/20/01
to
This is a small example of using post to send data to web server.

There is two different ways to do this operation.

Example 1:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Const
CRLF = #13#10;
Var
aStream: TMemoryStream;
Params: TMemoryStream;
S: String;
begin
aStream := TMemoryStream.create;
Params := TMemoryStream.Create;

HTTP.Request.ContentType := 'multipart/form-data;
boundary=-----------------------------7cf87224d2020a';

try
S := '-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="sys_return_url"' + CRLF + CRLF
+
'hello' + CRLF +
'-----------------------------7cf87224d2020a--';

Params.Write(S[1], Length(S));

with HTTP do begin
try
HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
<----------------------------------------------------------------->


Example 2:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Var
aStream: TMemoryStream;
Params: TStringStream;
begin
aStream := TMemoryStream.create;
Params := TStringStream.create('');
HTTP.Request.ContentType := 'application/x-www-form-urlencoded';

try
Params.WriteString(URLEncode('sys_return_url=' + 'helo' + '&'));
Params.WriteString(URLEncode('sys_return_url=' + 'helo'));
with HTTP do begin
try
HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
<----------------------------------------------------------------->

As you can see there is a difference in the way post stream is constructed
and the ContentType. In the first example ContentType is
"multipart/form-data; boundary=-----------------------------7cf87224d2020a"
and this boundary is used to separate different parameters.

In the second example the ContentType is
"application/x-www-form-urlencoded".
In this case the paremeteras are passed in the form

ParamName=ParamValue&ParamName=ParamValue

Note that the Pramaeters in the second form must be URL encoded.

Where these two formats of post information are used?

The first one is used when you have binary data to post and the second one
is when you are going to post only text fields.

Doychin
doi...@5group.com

"Sean" <Mc...@Consultant.com> wrote in message
news:96tboa$b0...@bornews.inprise.com...

Sean

unread,
Feb 21, 2001, 2:37:20 AM2/21/01
to
thx !!!


"Doychin Bondzhev" <doi...@5group.com> wrote in message
news:3a92e252_1@dnews...

Sean

unread,
Feb 21, 2001, 3:31:22 AM2/21/01
to
um, like, none of those examples worked, still get message parameter not
found.
I'm using cold fusion as the server and looking for form.fieldname for form
submissions
and url.fieldname for encoded url submissions. Nutting works. AAARRGGHH

ciao


"Doychin Bondzhev" <doi...@5group.com> wrote in message
news:3a92e252_1@dnews...

Doychin Bondzhev

unread,
Feb 21, 2001, 4:13:03 AM2/21/01
to
Can you send me a details about the form you are trying to submit ?

doychin

"Sean" <Mc...@Consultant.com> wrote in message

news:96vueg$36...@bornews.inprise.com...

Sean

unread,
Feb 21, 2001, 6:05:41 AM2/21/01
to
There is no form as yet, I am just trying to get cold fusion to see the
posted field.
Once I'm over that hurdle, then I'll create the form.

I just used your example and replaced 'name="sys_return_url"' with
'name="Name"'. Then in my Cold Fusion page I have #form.Name#
which would work with normal webposting.

I get this error:
Error Occurred While Processing Request
Error Diagnostic Information
An error occurred while evaluating the expression: #form.Name#
Error near line 1, column 15.
The specified FORM field cannot be found. This problem is very likely due to
the fact that you have misspelled the parameter name.
Date/Time: 02/21/01 13:07:37
Browser: Mozilla/3.0 (compatible; Indy Library)

thx

"Doychin Bondzhev" <doi...@5group.com> wrote in message

news:9700r4$38...@bornews.inprise.com...

Jacob Williams

unread,
Mar 19, 2001, 9:54:56 PM3/19/01
to
HI all,

hopefully someone out there can help me with this one as it is starting to
really bug me...

my situation is that I am trying to put together some code that allows our
POS & DB system at the office to communicate with our online store website
for the retrieval of information. We do not host the online store ourselves
so we do not have "direct" access to it. (If it were my call we woul dbe
running our own webserver and dedicated connection here)

In my test environment I have managed to get a program to send 1 form field
to the website and retrieve the correct/expected/desired response based on
the input. The webserver is a win2K box running the coldfusion application
server. I am using the Indy components for the HTTP communication, along
with other components for XML parsing (to parse the response for the
required information)

When I extended the code to attempt to send multiple form fields/variables
to the server I am getting the following error:

<HTML><HEAD><TITLE>Form Entries Incomplete or
Invalid</TITLE></HEAD><BODY><HR><H3>Form Entries Incomplete or
Invalid</H3>One or more problems exist with the data you have
entered.<UL><LI>1234<P></UL>Use the <I>Back</I> button on your web browser
to return to the previous page and correct the listed
problems.<P><HR></BODY></HTML>

I am using the "second" method from the below post and the encoding is
currently done as shown in the code snippet for the form variables. I am
only trying to send single word values with no special characters so have
not bothered to URLEncode the values as it would make no change.

Could someone please give me some idea as to where I might be going wrong.

thanks
Jacob


---------------[snip]---------------
Var
aStream : TMemoryStream; // response from webserver
Params : TStringStream; // data to be posted to the webserver

---------------[snip]---------------
// Set the content type of the request
HTTP.Request.ContentType := 'application/x-www-form-urlencoded';

try
// Set the parameters for the request
Params.WriteString('table_name='+tablename.text+'&');
Params.WriteString('field_name='+fieldname.text+'&');
Params.WriteString('val_required='+valuerequired.text);
StatusBar1.Panels[0].Text := Params.DataString;

with HTTP do begin
try

// Make the request (Post the data)
HTTP.Post(Edit1.Text,Params,aStream);


except
on E: Exception do

showmessage('Error encoutered during POST: ' + E.Message);
end;
end;
---------------[snip]---------------

"Sean" <Mc...@Consultant.com> wrote in message

news:96vr72$cf...@bornews.inprise.com...

Jacob Williams

unread,
Mar 19, 2001, 11:02:29 PM3/19/01
to
Dont worry,

it just didnt like the variable name I was using. I had val_required which
i changed to dat_field and it now works....
damntouchynamethingthatstumpedme.


"Jacob Williams" <ja...@qbdthebookshop.com> wrote in message
news:3ab6c5d7_2@dnews...

0 new messages