Delphi IdHTTP post 提交 json


本文整理自网络,侵删。

 
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdTCPConnection, IdTCPClient, IdHTTP,
  IdBaseComponent, IdComponent, IdIOHandler, IdIOHandlerSocket,
  IdIOHandlerStack, IdSSL, IdSSLOpenSSL, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
    btnPost: TButton;
    IdHTTP1: TIdHTTP;
    procedure FormCreate(Sender: TObject);
    procedure btnPostClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnPostClick(Sender: TObject);
var
  postStream: TStringStream;
  AEnctryRespose: string;
  url: string;
  aEnctryPost: string;
begin
  url := 'https:/xxx.xx';
  aEnctryPost := '{"username":"test","password":"1"}';
  postStream := TStringStream.Create(aEnctryPost);
  try
    postStream.Position := 0;
    AEnctryRespose := IdHTTP1.Post(url, postStream);
    ShowMessage(AEnctryRespose);//post后的返回内容
  finally
    IdHTTP1.Disconnect;
    FreeAndNil(postStream);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  IdHTTP1 := TIdHTTP.Create(nil);
  IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  IdHTTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
  IdHTTP1.HandleRedirects := True;
  IdHTTP1.Request.ContentType := 'application/json';//设置交互方式为json格式
end;

相关阅读 >>

Delphi 排列桌面图标

Delphi 安卓图像压缩bitmapcompress

Delphi与进程、窗口句柄、文件属性、程序运行状态

Delphi timer定时器使用

Delphi 判断一个颜色是否是亮色

Delphi edit1.gettextlen 获取编辑框字符数

orangeui作者开源作品

Delphi xe7实现的登录窗体的正确用法示例

Delphi 内存管理1

Delphi 判断tcp端口是否被占用的方法

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



打赏

取消

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

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

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

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

评论

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