Solved

sending data pack with POST to script...

Posted on 2004-03-27
3
182 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
  • 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

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

Title # Comments Views Activity
Delphi XE10 Round Image 2 79
delphi parse string to params 3 100
Reconfigure Delphi Install? 2 47
LAN or WAN ? 11 82
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

27 Experts available now in Live!

Get 1:1 Help Now