delphi idhttp post json 上传 PHP 接收


本文整理自网络,侵删。

 
前提:PHP端用$_post 接收

一、delphi idhttp post 上传数据 时如果使用 temp_stream: TStringStream;  内存流的方式上传 则需要指明IDHTTP的contentype

var
  idhttp2: TIdHTTP;
  temp_stream: TStringStream;
  temp_url: string;
  temp_str: string;
  strlist_para:TStringList;
begin
  strlist_para:=TStringList.Create();
  idhttp2 := TIdHTTP.Create(nil);
  strlist_para.Add('xx={"i":"5","billids":[{"id":1},{"id":2},{"id":3}]}') ;
  idhttp2.ReadTimeout := 10000; // 请求超时设置
  idhttp2.Request.ContentType := 'application/x-www-form-urlencoded';
  temp_stream := TStringStream.Create(AnsiToUtf8('xx='+json.AsString)); // 创建一个包含JSON数据的变量
  temp_stream.Position := 0; // 将流位置置为0
  temp_stream.SaveToFile('c:\123.txt');
  temp_stream.Position := 0; // 将流位置置为0
  temp_url := '地址';
  try
    temp_str := idhttp2.Post(temp_url, temp_stream);
  except
    temp_str := '';
  end;
  idhttp2.Free();
  temp_stream.Free;
  result := temp_str;
二、strlist_para:TStringList;方式上传

var
  idhttp2: TIdHTTP;
  temp_stream: TStringStream;
  temp_url: string;
  temp_str: string;
  strlist_para:TStringList;
begin
  strlist_para:=TStringList.Create();
  idhttp2 := TIdHTTP.Create(nil);
  strlist_para.Add('xx={"i":"5","billids":[{"id":1},{"id":2},{"id":3}]}') ;
  idhttp2.ReadTimeout := 10000; // 请求超时设置
  idhttp2.Request.ContentType := 'application/x-www-form-urlencoded';
  temp_stream := TStringStream.Create(AnsiToUtf8('xx='+json.AsString)); // 创建一个包含JSON数据的变量
  temp_stream.Position := 0; // 将流位置置为0
  temp_stream.SaveToFile('c:\123.txt');
  temp_stream.Position := 0; // 将流位置置为0
  temp_url := '地址';
  try
    temp_str := idhttp2.Post(temp_url, strlist_para);
  except
    temp_str := '';
  end;
  idhttp2.Free();
  temp_stream.Free;
  result := temp_str;

――――――――――――――――

原文链接:https://blog.csdn.net/weixin_44387646/article/details/103709801

相关阅读 >>

Delphi中比较两个字符串相似性的百分比算法

Delphi tclientdataset的使用

Delphi setwindowshookex - 设置钩子 unhookwindowshookex - 卸掉钩子

Delphi xe5 android 调用手机震动

Delphi fdconnection1.gettablenames 查看所有表包含用户表和系统表

Delphi 更改窗体为顶层窗体不闪烁

Delphi 窗体置顶(总在最前面)

Delphi tstringlist stringlist的特殊用法

Delphi列表控件tlistview定位到某一行

Delphi 除法 "/" 与 div 的不同

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



打赏

取消

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

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

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

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

评论

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