Solved

sending data pack with POST to script...

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

13 Experts available now in Live!

Get 1:1 Help Now