求idhttp post例子
找了半天没有post例子,谁能发个,小弟学习下!!!
小弟感激不尽啊!!!
[解决办法]
function Login(const Username,Password: string): Boolean;
var
html :string;
begin
Result :=False;
Account :=UserName;
IndyHttp :=TIdHTTP.Create(nil);
IndyCookieManager :=TIdCookieManager.Create(nil);
IndyHttp.CookieManager :=IndyCookieManager;
IndyZlib :=TIdCompressorZLibEx.Create(nil);
IndyHttp.Compressor :=IndyZlib;
PostParams :=TStringList.Create;
IndyHttp.Request.CacheControl :='no-cache';
IndyHttp.Request.Connection :='Keep-Alive';
IndyHttp.Request.Accept :='text/html, application/xhtml+xml, */*';
IndyHttp.Request.ContentType :='application/x-www-form-urlencoded';
IndyHttp.HandleRedirects :=True;
IndyHttp.AllowCookies :=True;
IndyHttp.HTTPOptions :=[hoForceEncodeParams];
IndyHttp.Get('http://192.168.0.1/Default.aspx');
PostParams.Clear;
PostParams.Add('account='+Username);
PostParams.Add('password='+Password);
IndyHttp.Request.Referer :='Referer http://192.168.0.1/Default.aspx';
html :=IndyHttp.Post('http://192.168.0.1/Login.ashx',PostParams);
if Pos('{Userinfo:[{result:"1"}]}',html)>0 then //ajax
Result :=True;
end;