Solved

sending data pack with POST to script...

Posted on 2004-03-27
3
184 Views
Last Modified: 2010-04-05
there are simple example how to send POST DATA
QUESTION : how i can send a lot off data whith one POST sending...


<?php
  if ((isset($_POST['username'])) && (isset($_POST['password']))) {
    echo 'OK';
  }  else {
    echo 'Error! Insufficient parameters!';
  }
?>

and at the Delphi side:

var
  ResultString: string;
  PostStrings: TStringList;
begin
  PostStrings := TStringList.Create;
  try
    PostStrings.Add('UserName=hello');
    PostStrings.Add('Password=world');
    ResultString := IdHTTP1.Post('http://www.test.com/login.php', PostStrings);
    if ResultString = 'OK' then
      ShowMessage('All OK!')
    else raise Exception.Create(ResultString);
  finally
    PostStrings.Free;
  end;
end;
0
Comment
Question by:andrezzz
[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
  • 2
3 Comments
 
LVL 1

Expert Comment

by:IrishFBall32
ID: 10695349
Im not exactly sure what you ment by sending a lot of data, so ill try to cover all the bases...

if by a lot of data you mean many variables then simply add more poststrings.add lines like so:
[code]
try
    PostStrings.Add('UserName=hello');
    PostStrings.Add('Password=world');
    PostStrings.Add('var1=foo');
    PostStrings.Add('var2=bar');
    PostStrings.Add('var3=blah1');
    PostStrings.Add('var4=blah2');
    ResultString := IdHTTP1.Post('http://www.test.com/login.php', PostStrings);
    <snip>
[/code]

If a lot of means a particularly large variable then you should be able to send it the same way you send the small ones as such:
[code]
try
    PostStrings.Add('UserName=reallyreallyreallyreallyreallyreallyreallyreallyreallylongusername');
    PostStrings.Add('Password=world');
    ResultString := IdHTTP1.Post('http://www.test.com/login.php', PostStrings);
    <snip>
[/code]

If you just mean being able to send the value of a variable then you can do the following:
[code]
var
  ResultString,
  UserNameString,
  PasswordString : string;
  PostStrings: TStringList;
<snip>
try
    PostStrings.Add('UserName='+UserNameString);
    PostStrings.Add('Password='+PasswordString);
    ResultString := IdHTTP1.Post('http://www.test.com/login.php', PostStrings);
    <snip>
[/code]
0
 

Author Comment

by:andrezzz
ID: 10695369
if one record is:
----- one record-------
name=some name
surname=same surname
date=reg date
info1= some information
info2= some information
...
info20= some information
---------------------
and I need to send about 100 this records with various data WITH ONE POST...

0
 
LVL 1

Accepted Solution

by:
IrishFBall32 earned 250 total points
ID: 10695830
i would have to say that as far as i know that cannot be done, at least not cleanly anyway...

you could try doing it by creating a record object like so...
type
  ARecord = record
    name,
    surname,
    info1,
    info2,
    ...
    info20 : string;
    regdate : tdatetime;
  end;
var
  allrecords : array of ARecord;
  i : integer;

Then the posting would go something like this...
for i := 0 to allrecords.high do begin
  poststrings.add('Record'+inttostr(i)+'='+allrecords[i]
end;
ResultString := IdHTTP1.Post('http://www.test.com/login.php', PostStrings);

The script for handling this data would have to be reworked to be able to handle any amount of variables in the form of Recordx where x represents the record number... It would also have to be able to parse out each record in order to get at its constituent parts, but that shouldnt be too hard...

that is the best i can think of for sending it in a single posting... out of curiosity why must it only use one post? The program could be much cleaner if each record could have its own post.
0

Featured Post

Industry Leaders: 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

Suggested Solutions

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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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