?
Solved

Use TIdHTTP to post data to ASP

Posted on 2003-02-25
3
Medium Priority
?
1,079 Views
Last Modified: 2010-08-05
Hi!
I would like to send data to an ASP-page on my homepage using the TIdHTTP component, but I can't figure out how. The ASP code that receives the data looks like this:

<%
Dim AName
Dim AAddress

AName = Request.Form("Name")
AAddress = Request.Form("Address")
%>

And I've tried this code in Delphi 6, but it doesn't work:

procedure TForm1.Button1Click(Sender: TObject);
var
  postdata : TStringlist;
  loutstream : TFileStream;
begin
  postdata := TStringlist.Create;
  loutstream := TFileStream.Create('c:\temp\svar.htm',fmCreate);
  try
    postdata.Add('Name=Johnnie');
    postdata.Add('Address=Walker');
    IdHTTP1.Post('http://localhost/fc/data/facterror.asp',postdata,loutstream);
  finally
    postdata.Free;
    loutstream.Free;
  end;
end;

Please help!

Regards, Daniel
0
Comment
Question by:Dippen
[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 2

Accepted Solution

by:
Tvigep earned 800 total points
ID: 8032561
why not simply do it through the URL?

procedure TForm1.Button1Click(Sender: TObject);
var myURL:string;
    Name:string;
    Address:string;
    ReturnedResult:string;
begin
  Name:='Johnnie';
  Address:='Walker';
  myUrl:='http://localhost/fc/data/facterror.asp?';
  myURL:=myURL+'?Name='+Name+'&Address='+Address';
  ReturnedResult:=idHTTP.Get(myURL);
end;

This also allows you to check the result your ASP-page returned.

HTH,
Stef
0
 

Author Comment

by:Dippen
ID: 8053710
I did do that and got strange error-codes back sometimes. Later I figured out that it depended on whether the fields had any spaces in them, and if I replaced the spaces with %20% it worked. So the problem has been solved, and I should have deleted the question if I could. But since your the first commentee(spelling?) you get the points instead. OK?
0
 
LVL 2

Expert Comment

by:Tvigep
ID: 8055667
Thanks! But a little addition: even if you use your method, this will be sent to the server through a URL. URL's may never contain  spaces, unless they are replaced  by %20. If there is a regular space in a URL, it will break off at that point. So if you tried to send

http://localhost/document.asp?Name=My Name&Address=Some street

the server will only see

http://localhost/document.asp?Name=My

and then it depends on what your ASP-page expects what kind of error messages that will throw.

Thanks
Stef
0

Featured Post

Technology Partners: 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

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 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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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