delphi通过Idhttp和php交互
最近需要做delphi和php交互的方法;
就把这2个方法写了下
一,Get方法
const Url = 'http://www.cnblogs.com';
procedure TForm1.Button1Click(Sender: TObject);
var
stream: TStringStream;
idHttpObj: TIdHTTP;
begin
try
stream := TStringStream.Create('', TEncoding.UTF8); //中文就不会乱码了
idHttpObj := TIdHTTP.Create(nil);
idHttpObj.Get(Url, stream);
Memo1.Text := stream.DataString;
finally
idHttpObj.Free;
stream.Free;
end;
二,POST方法,优点是比Get安全,我是通过json格式传送的;
(*********************************************************
获取web返回的信息
paramJson 参数,格式如下
'{"name":"myname","ID":"12356"}'
*********************************************************)
function GetWebData(URL:string;paramJson:string):string;stdcall;
var
slist : TStringList;
http : TIdHttp;
begin
try
http := TIdHttp.Create;
slist := TStringList.Create;
slist.Text := 'json='+paramJson;//加入json,方便php调用
result := http.Post(URL,slist);
finally
http.Free;
slist.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.lines.Add( GetWebData(URL,'{"key":"DFDGBFSE$#$$R","name":"中文","id":123456}') );
end;
通过PHP获取delphi发生的数据
<?php
$value = json_decode( $_POST['json'] );
var_dump($value);
?>
delphi通过Idhttp和php交互的更多相关文章
- [delphi]indy idhttp post方法
网易 博客 LOFTCam-用心创造滤镜 LOFTER-最美图片社交APP 送20张免费照片冲印 > 注册登录 加关注 techiepc的博客 万事如意 首页 日志 LOFTER 相册 音乐 ...
- Delphi Indy IDHttp 403 forbidden
http://hbk777.blog.163.com/blog/static/6058086200681594333361/ Delphi Indy IDHttp 403 forbidden 2006 ...
- Delphi的idhttp报IOHandler value is not valid错误的原因[转]
出现这种问题的原因是由于访问的 URL地址为https或存在其跳转地址为https. 首先单纯使用idhttp是只能访问http,而https则需要搭配IdSSLIOHandlerSocketOpen ...
- Delphi的idhttp报508 Loop Detected错误的原因
一般是访问https时才出现“508 Loop Detected”,idhttp+IdSSLIOHandlerSocketOpenSSL,这个在上篇文章中讲过了. 由于该问题网上资料极少,连外文资料也 ...
- Delphi的idhttp报IOHandler value is not valid错误的原因
出现这种问题的原因是由于访问的 URL地址为https或存在其跳转地址为https. 首先单纯使用idhttp是只能访问http,而https则需要搭配IdSSLIOHandlerSocketOpen ...
- delphi 用idhttp做web页面数据抓取 注意事项
这里不讨论webbrowse方式了 .直接采用indy的 idhttp Get post 可以很方便的获取网页数据. 但如果要抓取大量数据 程序稳定运行不崩溃就不那么容易了.这几年也做了不少类似工具 ...
- delphi indy Idhttp error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version
在使用 indy 中的 idhttp 组件访问 https 网站时,出现如下错误: error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert pr ...
- delphi请求idhttp数据
idhttp ss : TStringStream; begin ss := TStringStream.)); { 指定gb2312的中文代码页,或者54936(gb18030)更好些 utf8 对 ...
- Delphi的IDHTTP的基本用法
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
随机推荐
- 安装npm install时,长时间停留在某一处的解决方案
默认情况npm install安装时,会从 github.com 上下载文件,大部分安装不成功的原因都源自这里 因为 GitHub Releases 里的文件都托管在 s3.amazonaws.com ...
- 工作总结 返回 json 后台对象中,某一个字段设为string 整个对象转换为json 返回到页面中
JsonRequestBehavior.AllowGet作用 若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet MVC 默认 Request 方式为 Po ...
- windows上IIS实现https,配置ssl证书
windows2012实现IIS7的https 1.申请证书,这里申请腾讯云的证书 1)登录腾讯云控制台,依次单击“云产品”>“SSL证书管理”>“申请证书” 2)在免费证书申请页面填写相 ...
- IBM Rational AppScan使用详细说明
转自:http://www.nxadmin.com/tools/675.html 本文将详细介绍Appscan功能选项设置的细节,适合E文一般,初次接触Appscan的童鞋参考阅读. Appscan是 ...
- 查看/设置MySQL数据库的事务隔离级别
查看InnoDB存储引擎 系统级的隔离级别 和 会话级的隔离级别: mysql> select @@global.tx_isolation,@@tx_isolation; +---------- ...
- 定时执行线程池ScheduledExecutorService的使用
ScheduledExecutorService progressExecutorService = Executors.newScheduledThreadPool(1); ScheduledFut ...
- LVM卷组命令
一般维护命令 #vgscan //检測系统中全部磁盘 #vgck [卷组名] //用于检查卷组中卷组描写叙述区域信息的一致性. #vgdisplay [卷组名] //显示卷组的属性信息 #vg ...
- Win7 64bit+Anaconda(3-5.0.1,Python3.6)+Pycharm(community-2017.3.3)+OpenCV(python‑3.4.0‑cp36‑cp36m)(转载)
Anaconda(3-5.0.1,Python3.6)下载链接:https://pan.baidu.com/s/1bqFwLMB 密码:37ih Pycharm(community-2017.3.3) ...
- 《Python基础教程》第20章学习笔记
python实现:https://github.com/captainwong/instant_markup c++实现:https://github.com/captainwong/instant_ ...
- 速记const 指针与指向const的指针
指向const的指针.它的意思是指针指向的内容是不能被改动的.它有两种写法. ` const int* p; (推荐) int const* p;` 再说const指针.它的意思是指针本身的值是不能被 ...