TNetHttpClient的用法

TNetHttpClient的用法

TNetHttpClient是DELPHI XE8新增加的控件。

在之前,我们一般都是使用IDHTTP控件,但在安卓、IOS等非WINDOWS平台,IDHTTP访问HTTPS却不行了。

大家知道INDY的SSL访问局限于WINDOWS平台,并不支持跨平台HTTPS访问。

鉴于以上原因,所以EMB才推出了TNetHttpClient。

TNetHttpClient既可以阻塞(如同INDY),又可以异步(这就很全面了)。

TNetHttpClient不再和INDY一样依赖OPENSSL。

unit Unit1;

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
  TForm1 = class(TForm)
    NetHTTPClient1: TNetHTTPClient;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    NetHTTPClient2: TNetHTTPClient;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure NetHTTPClient1RequestCompleted(const Sender: TObject;
      const AResponse: IHTTPResponse);
    procedure Button2Click(Sender: TObject);
    procedure NetHTTPClient2RequestCompleted(const Sender: TObject;
      const AResponse: IHTTPResponse);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses System.NetEncoding;

{$R *.dfm}


function UrlDecode(const AStr: AnsiString): AnsiString;
var
  Sp, Rp, Cp: PAnsiChar;
  s: AnsiString;
begin
  SetLength(Result, Length(AStr));
  Sp := PAnsiChar(AStr);
  Rp := PAnsiChar(Result);
  Cp := Sp;
  while Sp^ <> #0 do
  begin
    case Sp^ of
      '+':
        Rp^

你可能感兴趣的:(json)