Delphi XE7写的一个http post的小测试程序


本文整理自网络,侵删。

 本文章介绍了Delphi XE7写的一个http post的小测试程序,该程序是通过TIdHTTP组件进行post功能的测试,具体就不介绍了,代码很简单,下面是主要的代码

unit Unit1;

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;

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  sl : TStringList;
  ResponseStream: TMemoryStream;
  resultBytes: TBytes;
begin
  sl := TStringList.Create;
  ResponseStream := TStringStream.Create;
  try
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
    sl.Add('id=' + Edit2.Text);
    IdHTTP1.Post(Edit1.Text, sl, ResponseStream);
    ResponseStream.Position := 0;

    SetLength(resultBytes, ResponseStream.Size);
    ResponseStream.ReadBuffer(resultBytes[0], Length(resultBytes));

    Memo1.Lines.Text := TEncoding.UTF8.GetString(resultBytes);
  finally
    sl.Free;
    ResponseStream.Free;
  end;
end;

end.

相关阅读 >>

Delphi实现分割文本文件的小程序

Delphi copyrect实现的几个图片的转换效果

Delphi 用iisreset命令重启iis

winapi 字符及字符串函数(14): chartooem、oemtochar

Delphi 用拼音首字符检索汉字的源代码

Delphi 随便找个网站获取格林威治时间, 并转换到北京时间

Delphi 判断字符串是否相同

Delphi image1 图像旋转90

decodedate:从一个tdatetime变量中提取年、月、日数值

winapi 字符及字符串函数(4): charupperbuff - 把缓冲区中指定数目的字符转大写

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...