httpclientforwindowsdemo [操作系统入门]

编程

httpclient for windows demo

unit FMain;

{

uses

Vcl.Forms,

FMain in ‘FMain.pas‘ {FormMain},

Grijjy.Http in ‘....GrijjyFoundationGrijjy.Http.pas‘,

Grijjy.SocketPool.Win in ‘....GrijjyFoundationGrijjy.SocketPool.Win.pas‘,

Grijjy.OpenSSL.API in ‘....GrijjyFoundationGrijjy.OpenSSL.API.pas‘,

Grijjy.OpenSSL in ‘....GrijjyFoundationGrijjy.OpenSSL.pas‘,

Grijjy.MemoryPool in ‘....GrijjyFoundationGrijjy.MemoryPool.pas‘,

Grijjy.Collections in ‘....GrijjyFoundationGrijjy.Collections.pas‘,

Grijjy.Winsock2 in ‘....GrijjyFoundationGrijjy.Winsock2.pas‘,

Grijjy.Uri in ‘....GrijjyFoundationGrijjy.Uri.pas‘,

Grijjy.BinaryCoding in ‘....GrijjyFoundationGrijjy.BinaryCoding.pas‘,

Nghttp2 in ‘..Nghttp2.pas‘;

}

interface

uses

Winapi.Windows,

Winapi.Messages,

System.SysUtils,

System.Variants,

System.Classes,

System.Messaging,

Vcl.Graphics,

Vcl.Controls,

Vcl.Forms,

Vcl.Dialogs,

Vcl.StdCtrls,

Grijjy.Http;

type

TFormMain = class(TForm)

EditUrl: TEdit;

MemoContent: TMemo;

MemoHeaders: TMemo;

LabelResponseHeaders: TLabel;

LabelResponseContent: TLabel;

ButtonGet: TButton;

ButtonGetNonBlocking: TButton;

procedure ButtonGetClick(Sender: TObject);

procedure ButtonGetNonBlockingClick(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

private

procedure HttpResponseMessageListener(const Sender: TObject;

const M: TMessage);

{ Private declarations }

public

{ Public declarations }

end;

var

FormMain: TFormMain;

implementation

{$R *.dfm}

procedure TFormMain.ButtonGetClick(Sender: TObject);

var

HTTP: TgoHttpClient;

begin

HTTP := TgoHttpClient.Create;

try

MemoContent.Text := HTTP.Get(EditUrl.Text);

MemoHeaders.Text := HTTP.ResponseHeaders.AsString;

finally

HTTP.Free;

end;

end;

procedure TFormMain.ButtonGetNonBlockingClick(Sender: TObject);

var

HTTP: TgoHttpClient;

begin

HTTP := TgoHttpClient.Create(True, False);

try

HTTP.Get(‘https://nghttp2.org‘);

finally

HttpClientManager.Release(HTTP);

end;

end;

procedure TFormMain.HttpResponseMessageListener(const Sender: TObject;

const M: TMessage);

var

HttpResponseMessage: TgoHttpResponseMessage;

begin

HttpResponseMessage := M as TgoHttpResponseMessage;

MemoContent.Text := HttpResponseMessage.HttpClient.BytesToString(HttpResponseMessage.Response, HttpResponseMessage.ResponseContentCharset);

MemoHeaders.Text := HttpResponseMessage.ResponseHeaders.AsString;

end;

procedure TFormMain.FormCreate(Sender: TObject);

begin

TMessageManager.DefaultManager.SubscribeToMessage(TgoHttpResponseMessage,

HttpResponseMessageListener);

end;

procedure TFormMain.FormDestroy(Sender: TObject);

begin

TMessageManager.DefaultManager.Unsubscribe(TgoHttpResponseMessage,

HttpResponseMessageListener);

end;

end.

  

httpclient for windows demo

以上是 httpclientforwindowsdemo [操作系统入门] 的全部内容, 来源链接: utcz.com/z/519471.html

回到顶部