码迷,mamicode.com
首页 > Windows程序 > 详细

httpclient for windows demo

时间:2021-01-14 11:34:15      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:unit   create   tpc   tostring   efault   arp   ade   roc   vat   

httpclient for windows demo

unit FMain;
{
uses
  Vcl.Forms,
  FMain in ‘FMain.pas‘ {FormMain},
  Grijjy.Http in ‘..\..\GrijjyFoundation\Grijjy.Http.pas‘,
  Grijjy.SocketPool.Win in ‘..\..\GrijjyFoundation\Grijjy.SocketPool.Win.pas‘,
  Grijjy.OpenSSL.API in ‘..\..\GrijjyFoundation\Grijjy.OpenSSL.API.pas‘,
  Grijjy.OpenSSL in ‘..\..\GrijjyFoundation\Grijjy.OpenSSL.pas‘,
  Grijjy.MemoryPool in ‘..\..\GrijjyFoundation\Grijjy.MemoryPool.pas‘,
  Grijjy.Collections in ‘..\..\GrijjyFoundation\Grijjy.Collections.pas‘,
  Grijjy.Winsock2 in ‘..\..\GrijjyFoundation\Grijjy.Winsock2.pas‘,
  Grijjy.Uri in ‘..\..\GrijjyFoundation\Grijjy.Uri.pas‘,
  Grijjy.BinaryCoding in ‘..\..\GrijjyFoundation\Grijjy.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

标签:unit   create   tpc   tostring   efault   arp   ade   roc   vat   

原文地址:https://www.cnblogs.com/hnxxcxg/p/14275426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!