Delphi http postWritten by Codes Tips on June 2,
Monster Headphones, 2009 � 9:42 am -
To post some data through http protocol in Delphi you can use TIDHttp component.TIDHttp has a function Post that takes 2,
Dre Beats Headphones, first parameter is the url where you wanna post data and the second is the data you need to post.The first parameter of Post function is a string and the second one is a TStringList.
Delphi sample code to post data through http. First put in the uses clause IdHTTP
function PostData:string;
var param:TStringList;
valid:boolean;
url,
Beats Headphones,text:string;
http:TIDHttp;
begin
http := TIDHttp.Create(nil);
http.HandleRedirects := true;
http.ReadTimeout := 5000;
param:=TStringList.create;
param.Clear;
param.Add('parameter1=1');
param.Add('parameter2=2');
param.Add('parameter3=3');
valid:=true;
url:='http://www.examplesite.com/script.php'; try
text:=http.Post(url,
Monster Beats Headphones,param); except
on E:Exception do
begin
valid:=false;
end; end;
if valid then PostData:= text
else PostData := '';
end;
You can call the function like this:
textPostData := PostData();
This function returns empty string if it was an error posting data,
monster pro headphones, if not it returns the text that is returned from the url that we posted data.
We created a new TIDHttp variable at runtime and put the properties ReadTimeout to 5 seconds(timeout of the connection) and HandleRedirects to true,
bose headphones, because the url where we post data can redirect us to other page from where we get the result.