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 tdirectory.tfilterpredicate

webbrowser点击没有id和name的按钮或链接

Delphi 用nethttpclient执行post操作遇到的问题

Delphi将图片缩放成指定大小

Delphi raise 语句: 抛出异常

Delphi 在线程中运行窗体

Delphi下调用有返回值的存储过程

Delphi intraweb 在iis下发布的web.config

Delphi 实现 图灵机器人api(idhttp post )

Delphi运行时拖拉、改变元件大小

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



打赏

取消

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

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

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

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

评论

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