INDY idhttp Post用法
http://www.cnblogs.com/tk-del/archive/2013/05/10/3071541.html
function Post(AURL: string; ASource: TIdStrings): string; overload;
function Post(AURL: string; ASource: TStream): string; overload;
function Post(AURL: string; ASource: TIdMultiPartFormDataStream): string; overload;
procedure Post(AURL: string; ASource: TIdMultiPartFormDataStream; AResponseContent: TStream); overload;
procedure Post(AURL: string; ASource: TIdStrings; AResponseContent: TStream); overload;
procedure Post(AURL: string; ASource, AResponseContent: TStream); overload;
其中的基本方法是下面的过程类方法,其他post重载方法均为嵌套使用此方法:
[delphi] view plaincopyprint?
procedure TIdCustomHTTP.Post(AURL: string; ASource, AResponseContent: TStream); 参数:
[delphi] view plaincopyprint?
AURL: string // post请求URL
ASource: TIdMultiPartFormDataStream // TStream派生的类,其中为发送的流数据及mime信息,可用于上传文件
ASource: TStream // 发送的流数据
AResponseContent: TStream // 响应内容流ASource: TIdStrings // TString派生的类,用于向服务器提交数据
ASource 为TIdStrings的数据,使用的MIME是默认的“application/x-www-form-urlencoded”,而TIdMultiFormDataStream则是根据发送的内容/文件来设定MIME类型。
示例:
[delphi] view plaincopyprint?
unit Umain; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls, IdMultipartFormData; type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Memo1: TMemo;
btnOne: TButton;
btnTwo: TButton;
btnThree: TButton;
btnFour: TButton;
btnFive: TButton;
btnSix: TButton;
procedure btnOneClick(Sender: TObject);
procedure btnTwoClick(Sender: TObject);
procedure btnThreeClick(Sender: TObject);
procedure btnFourClick(Sender: TObject);
procedure btnFiveClick(Sender: TObject);
procedure btnSixClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} const
sPostUrl = 'http://cne.csu.edu.cn/reg/mima-pass.asp?path='; procedure TForm1.btnOneClick(Sender: TObject);
var
postcmd : TStringList;
begin
postcmd := TStringList.Create; // 组合参数列表
postcmd.Add('AutoGet=1');
postcmd.Add('Logintype=0');
postcmd.Add('password=test');
postcmd.Add('username=test');
Memo1.Text := IdHTTP1.Post(sPostUrl, postcmd); // 以post的方式发送到服务器
end; procedure TForm1.btnTwoClick(Sender: TObject);
var
postStream : TStringStream;
begin
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded'; // 定义发送mime类型
postStream := TStringStream.Create('AutoGet=1&Logintype=0&password=test&username=test'); // 发送内容
Memo1.Text := IdHTTP1.Post(sPostUrl, postStream);
end; procedure TForm1.btnThreeClick(Sender: TObject);
var
postStream : TIdMultiPartFormDataStream;
begin
IdHTTP1.HandleRedirects := true; // 允许重定向,因为这个站点会发生重定向
IdHTTP1.Request.Referer := 'http://www.qiuziti.com/'; // 设置来路,此网站要求 postStream := TIdMultiPartFormDataStream.Create; // 创建TIdMultiPartFormDataStream类 postStream.AddFormField('textfield', 'd:\temp\test.png'); // 表单参数
postStream.AddFile('uploaded_file', 'd:\temp\test.png', 'image/png'); // 表单文件
Memo1.Text := Utf8ToAnsi(IdHTTP1.Post('http://www.qiuziti.com/s/upload.ashx', postStream));
end; procedure TForm1.btnFourClick(Sender: TObject);
var
postStream : TIdMultiPartFormDataStream;
respStream : TStringStream;
begin
IdHTTP1.HandleRedirects := true; // 允许重定向,因为这个站点会发生重定向
IdHTTP1.Request.Referer := 'http://www.qiuziti.com/'; // 设置来路,此网站要求 postStream := TIdMultiPartFormDataStream.Create; // 创建TIdMultiPartFormDataStream类
respStream := TStringStream.Create(''); postStream.AddFormField('textfield', 'd:\temp\test.png'); // 表单参数
postStream.AddFile('uploaded_file', 'd:\temp\test.png', 'image/png'); // 表单文件 IdHTTP1.Post('http://www.qiuziti.com/s/upload.ashx', postStream, respStream);
Memo1.Text := Utf8ToAnsi(respStream.DataString);
end; procedure TForm1.btnFiveClick(Sender: TObject);
var
respStream : TStringStream;
postcmd : TStringList;
begin
postcmd := TStringList.Create;
respStream := TStringStream.Create('');
postcmd.Add('AutoGet=1');
postcmd.Add('Logintype=0');
postcmd.Add('password=test');
postcmd.Add('username=test');
IdHTTP1.Post(sPostUrl, postcmd, respStream);
Memo1.Text := respStream.DataString;
end; procedure TForm1.btnSixClick(Sender: TObject);
var
postStream, respStream : TStringStream;
begin
postStream := TStringStream.Create('AutoGet=1&Logintype=0&password=test&username=test');
respStream := TStringStream.Create('');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded'; // 定义发送mime类型
IdHTTP1.Post(sPostUrl, postStream, respStream);
Memo1.Text := respStream.DataString;
end; end.
INDY idhttp Post用法的更多相关文章
- [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 实战用法(TIdhttpEx)
以delphi XE8 自带indy(10.5.8.0)组件为例,分享实战中遇到的问题及解决方法. TIdHttpEx 用法实例01[多线程获取网页](包含完整源码) 实例02(如何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 ...
- idhttp的用法
1)POST function PostMethod(http: TIDhttp; URL: string; Params: TStringList): string;var RespData: TS ...
- IdHttp 资料
http://blog.csdn.net/delphizhou/article/details/3085704 IdHttp 资料 网上找了些不过很不好找.今天找了些收藏在一起.以便他人查阅, idh ...
- Delphi QC 记录
各网友提交的 QC: 官方网址 说明 备注 https://quality.embarcadero.com/browse/RSP-12985 iOS device cannot use indy id ...
- IDHttp的基本用法(转)
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
- Delphi的IDHTTP的基本用法
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
随机推荐
- 转-sketch技巧
10个帮你UI设计提速的Sketch使用技巧 2015-4-11 09:59| 发布者: yuanxingbbs| 查看: 1129| 评论: 0 选择使用Sketch的理由很多,因为好奇跟风安装 ...
- ACM2050前传
n在一个平面上有一个圆和n条直线,这些直线中每一条在圆内 同其他直线相交,假设没有3条直线相交于一点,试问这些直线 将圆分成多少区域. 使用递归 F(1)=2; F(n) = F(n-1)+n; ...
- android系统的文件夹选择器
aFileChooser: https://github.com/iPaulPro/aFileChooser/issues, 这个是最适合android的文件选择器,看看有无可能改成文件夹选择器. f ...
- Cocos2d-x项目移植到WinRT/Win8小记
Cocos2d-x项目移植到WinRT/Win8小记 作者: K.C. 日期: 11/17/2013 Date: 2013-11-17 23:33 Title: Cocos2d-x项目移植到WinRT ...
- ESB服务号列表
用于以下两个网址: -浙商ESB调用规范- xml格式 -浙商ESB调用规范- json格式 ESB服务号<SERVICE_NO>{serviceNo} 接口中文意思 42000000 ...
- 理解js闭包(一)
@(编程) 闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. ...
- HDU 5444 Elven Postman (二叉树,暴力搜索)
题意:给出一颗二叉树的先序遍历,默认的中序遍历是1..2.……n.给出q个询问,询问从根节点出发到某个点的路径. 析:本来以为是要建树的,一想,原来不用,其实它给的数是按顺序给的,只要搜结点就行,从根 ...
- [hihoCoder]#1039 : 字符消除
Description 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消除过程是如下进行的: 1)如果s包含长度超过1的由相同字母组成的子串,那么这些 ...
- 利用C#实现对excel的写操作
一.COM interop 首先我们要了解下何为COM Interop,它是一种服务,可以使.NET Framework对象能够与COM对象通信.Visual Studio .NET 通过引入面向公共 ...
- CloudStack服务引擎配置(cloud-engine-service模块)
"?> <!--CloudStack服务引擎配置--> <beans xmlns="http://www.springframework.org/schem ...