2018-09-30 post

2018-09-30  本文已影响0人  netppp

unit Unit2;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,

  IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, IdIOHandler,

  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL;

type

  TForm2 = class(TForm)

    Button1: TButton;

    IdHTTP1: TIdHTTP;

    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;

    procedure Button1Click(Sender: TObject);

    procedure IdSSLIOHandlerSocketOpenSSL1GetPassword(var Password: string);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);

var

  IdHttp1: TIdHTTP;

  Url,s,ResponseStr: string;//请求地址

  ResponseStream : TStringStream; //返回信息

  RequestList : TStringList;    //请求信息

  RequestStream : TStringStream;

begin

  //创建IDHTTP控件

  IdHttp1:= TIdHTTP.Create(nil);

  //TStringStream对象用于保存响应信息

  ResponseStream := TStringStream.Create('');

  RequestStream := TStringStream.Create('');

  RequestList := TStringList.Create;

  idhttp1.HandleRedirects:=true;  //这行去掉后,不能正常运行

//idhttp1.Request.ContentType := 'application/x-www-form-urlencoded'; //没这行,会造成流的方式无法提交成功,列表式提交没有影响

url := 'http://www.ewebeditor.net/ewebeditor/admin/login.asp?action=login';

      //以列表的方式提交参数

    RequestList.Add('h=www.ewebeditor.net');

    RequestList.Add('pwd=admin');

    RequestList.Add('usr=admin');

    IdHttp1.Post(url,RequestList,ResponseStream);

  //    RequestStream.WriteString('h=www.ewebeditor.net&pwd=admin&usr=admin');  //以流的方式提交参数

//    IdHttp1.Post(Url,RequestStream,ResponseStream);

      IdHttp1.get('http://www.ewebeditor.net/ewebeditor/admin/default.asp',ResponseStream);

      IdHttp1.get('http://www.ewebeditor.net/ewebeditor/admin/main.asp',ResponseStream);

      IdHttp1.get('http://www.ewebeditor.net/ewebeditor/admin/menu.asp',ResponseStream);

    //获取网页返回的信息

    ResponseStr := ResponseStream.DataString;

    //网页中的存在中文时,需要进行UTF8解码

    s := UTF8Decode(ResponseStr);

    showmessage(s);

    IdHttp1.Free;

    RequestList.Free;

    RequestStream.Free;

    ResponseStream.Free;

{

      http://www.ewebeditor.net/ewebeditor/admin/login.asp  登录名admin 密码admin

      经过火狐浏览器F12抓包,取得POST的网址,和提交的三个参数,就可以了

    }

end;

{如果使用NETHTTPCLIENT组件,那么添加SSL组件问题不存在,用IDHTTP和用NETHTTPCLIENT返回的信息是不同的,用IDHTTP的信息更全面}

end.

.

wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

NETHTTPCLIENT组件

unit Unit2;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Net.URLClient,

  System.Net.HttpClient, System.Net.HttpClientComponent, Vcl.StdCtrls;

type

  TForm2 = class(TForm)

    Button1: TButton;

    NetHTTPClient1: TNetHTTPClient;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);

var

  Url,s,ResponseStr: string;//请求地址

  ResponseStream : TStringStream; //返回信息

  RequestList : TStringList;    //请求信息

  RequestStream : TStringStream;

begin

  //TStringStream对象用于保存响应信息

  ResponseStream := TStringStream.Create('');

  RequestStream  := TStringStream.Create('');

  RequestList := TStringList.Create;

  nethttpclient1.ContentType := 'application/x-www-form-urlencoded'; //没这行,会造成流的方式无法提交成功,列表式提交没有影响

  Url := 'http://www.ewebeditor.net/ewebeditor/admin/login.asp?action=login';

  {  //以列表的方式提交参数

    RequestList.Add('h=www.ewebeditor.net');

  RequestList.Add('pwd=admin');

  RequestList.Add('usr=admin');

    nethttpclient1.Post(url,RequestList,ResponseStream);

  }

  RequestStream.WriteString('h=www.ewebeditor.net&pwd=admin&usr=admin');  //以流的方式提交参数

// RequestStream.Seek(0,tseekorigin.sobeginning);

    RequestStream.position:=0;  //如果使用nethttpclient控件用流的方式提交,那么需要将起始置为0,要启用这一句或上面那一句,列表式提交没影响

      nethttpclient1.Post(Url,RequestStream,ResponseStream);

      nethttpclient1.get('http://www.ewebeditor.net/ewebeditor/admin/default.asp',ResponseStream);

      nethttpclient1.get('http://www.ewebeditor.net/ewebeditor/admin/main.asp',ResponseStream);

      nethttpclient1.get('http://www.ewebeditor.net/ewebeditor/admin/menu.asp',ResponseStream);

    //获取网页返回的信息

    ResponseStr := ResponseStream.DataString;

    //网页中存在中文时,需要进行UTF8解码

    s:= UTF8Decode(ResponseStr);

    showmessage(s);

    nethttpclient1.Free;

    RequestList.Free;

    RequestStream.Free;

    ResponseStream.Free;

{

      http://www.ewebeditor.net/ewebeditor/admin/login.asp  登录名admin 密码admin

      经过火狐浏览器F12抓包,取得POST的网址,和提交的三个参数,就可以了

    }

end;

//如果使用NETHTTPCLIENT组件,那么添加SSL组件问题不存在

end.

上一篇下一篇

猜你喜欢

热点阅读