indy组件idhttp用post返回response的例子,DELPHI7,INDY10运行通过

     

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  LoginInfo:TStrings;
  Response:TStringStream;
  i:Integer;
  Cookie:string;
begin
  Cookie:='';
  Response := TStringStream.Create('');
  LoginInfo := TStringList.Create;
  try
    LoginInfo.Clear;
    LoginInfo.Add('ip='+trim(form1.Edit1.Text));
    //IdHTTP1.Request.Referer:='http://ip.987654.com/index.asp';
    //IdHTTP1.Request.From :='http://ip.987654.com/index.asp';
    try
      IdHTTP1.Post('http://ip.987654.com/index.asp',LoginInfo,Response);
    except
      showmessage('登陆失败');
    end;
    showmessage(Response.DataString);    //从返回的页面中找出cookie
  finally
    LoginInfo.Free;
    Response.Free;
  end;
end;


end.




评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.