To post some data through http protocol in Delphi you can use TIDHttp component.
TIDHttp has a function Post that takes 2, 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,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,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, 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, because the url where we post data can redirect us to other page from where we get the result.


















No comments yet.
Leave a comment
You must be logged in to post a comment.