如何做一个用post方式发布数据的程序?
就是将本地数据 通过idhttp或者别的控件的 post方法,来把数据提交到网站后台上?先进行抓包,然后通过抓取到的cookie来 发布数据?哪位仁兄可以帮忙 写个实例代码??可以加更多的分!
就是将本地数据 通过idhttp或者别的控件的 post方法,来把数据提交到网站后台上?先进行抓包,然后通过抓取到的cookie来 发布数据?哪位仁兄可以帮忙 写个实例代码??可以加更多的分!
或者直接弄一个隐藏的窗口放一个浏览器控件.操作控件.
//自己定义的类,我懒得重新写代码了~~你把核心代码看了就好了TWebForm = class(TObject)
private
FMethod:string;
FAction:string;
FName:String;
FInputs:TList;
function GetCount:Integer;
function GetInput(Index:Integer):TInputElement;
public
constructor Create; overload;
constructor Create(const FormStr:string); overload;
destructor Destroy; override;
procedure Free;
procedure AddInputElement(InputStr:string); overload;
procedure AddInputElement(Name,Id,Value:String); overload;
procedure DelInputElement(index:Integer);
procedure AddWebForm(FormStr:String);
procedure SetWebForm(FormStr:String);
property Name:String read FName write FName;
property Action:String read FAction write FAction;
property Method:String read FMethod write FMethod;
property Count:Integer read GetCount;
property Inputs[Index:Integer]:TInputElement read GetInput; default;
function InputOf(name:string):TInputElement;
function GetPars:TStrings;
procedure Clear;
end;function TBaidu.GetPage(Url: string):String;
begin
try
FIdHttp.Request.Referer:=Url;
FIdHttp.Request.From:=HomeUrl;
if Assigned(FOnGetPage) then FOnGetPage(Self);
Result:=FIdhttp.Get(Url);
FHtml:=Result;
FUrl:=Url;
except
on E:Exception do
MessageBox(0,PChar('获取页面错误!错误内容:'+E.Message),PChar('获取错误'), MB_OK or MB_ICONERROR);
end;
end;function TBaidu.Login(const UserName: string; const Password: string):Boolean;
var
LoginForm:TWebForm;
Response:String;
I:Integer;
begin
//初始化
result:=false;
FWebPage.Clear;
FIdhttp.Request.Clear;
//获取并分析登陆页面
FUrl:=LoginUrl;
ProcPage(GetPage(LoginUrl)); FUserName:=UserName;
FPassword:=Password;
LoginForm:=FWebPage[0];
//设置用户名和密码
if Assigned(LoginForm.InputOf('username')) then
LoginForm.InputOf('username').Value:=FUserName;
if Assigned(LoginForm.InputOf('password')) then
LoginForm.InputOf('password').Value:=FPassword; //设置登陆信息
FIdhttp.Request.Referer:=LoginUrl;
FIdhttp.Request.From:=HomeUrl;
FIdhttp.HandleRedirects:=true;
FIdhttp.RedirectMaximum:=1;
//发生事件
if Assigned(FOnLogin) then FOnLogin(Self);
try
Response:=FIdhttp.Post(LoginUrl,LoginForm.GetPars); //这里的GetPars下面有详细
except
on E:Exception do
MessageBox(0,PChar('登录时发生错误!错误信息:'+E.Message),PChar('登陆错误'),MB_OK or MB_ICONERROR);
end; for i := 0 to FIdHttp.Response.RawHeaders.Count - 1 do
begin
if UpperCase(Copy(FIdHttp.Response.RawHeaders[i],1,10)) = 'SET-COOKIE' then
begin
FCookie := Trim(Copy(FIdHttp.Response.RawHeaders[i],12,MaxInt));
FCookie :=Copy(Cookie,1,Pos(';',Cookie));
FCookieList := FCookieList + Cookie;
end;
end;
FIdHttp.Request.RawHeaders.Add('Cookie: '+FCookieList); //初始化空间
FUrl:=CenterUrl;
FSpaceUrl:=GetSpaceUrl(GetPage(CenterUrl));
FWebPage.SetWebPage(FHtml); //初始化上传页面
FUrl:=SpaceUrl + UploadUrl;
FWebPage.SetWebPage(GetPage(FUrl)); if Length(FCookieList)>200 then Result:=true;
end;function TWebForm.GetPars:TStrings;
var i:integer;
begin
Result:=TStringList.Create;
for I := 0 to FInputs.Count - 1 do
begin
if trim(TInputElement(FInputs[i]).GetPar)<>'' then Result.Add(TInputElement(FInputs[i]).GetPar);
end;
end;
基本上就是这样了~~构造一个输出流,然后通过Post方法提交出去,然后得到Cookie,至于后台操作Web浏览器~~很简单,我就不说了
我有源码,QQ:7552667