?
Solved

sending data pack with POST to script...

Posted on 2004-03-27
3
Medium Priority
?
190 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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