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用法的更多相关文章

  1. [delphi]indy idhttp post方法

    网易 博客 LOFTCam-用心创造滤镜 LOFTER-最美图片社交APP 送20张免费照片冲印 > 注册登录  加关注 techiepc的博客 万事如意 首页 日志 LOFTER 相册 音乐 ...

  2. Delphi Indy IDHttp 403 forbidden

    http://hbk777.blog.163.com/blog/static/6058086200681594333361/ Delphi Indy IDHttp 403 forbidden 2006 ...

  3. delphi idhttp 实战用法(TIdhttpEx)

    以delphi XE8 自带indy(10.5.8.0)组件为例,分享实战中遇到的问题及解决方法. TIdHttpEx 用法实例01[多线程获取网页](包含完整源码) 实例02(如何Post参数,如何 ...

  4. 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 ...

  5. idhttp的用法

    1)POST function PostMethod(http: TIDhttp; URL: string; Params: TStringList): string;var RespData: TS ...

  6. IdHttp 资料

    http://blog.csdn.net/delphizhou/article/details/3085704 IdHttp 资料 网上找了些不过很不好找.今天找了些收藏在一起.以便他人查阅, idh ...

  7. Delphi QC 记录

    各网友提交的 QC: 官方网址 说明 备注 https://quality.embarcadero.com/browse/RSP-12985 iOS device cannot use indy id ...

  8. IDHttp的基本用法(转)

    一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...

  9. Delphi的IDHTTP的基本用法

    一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...

随机推荐

  1. c/c++ 数字转成字符串, 字符串转成数字

    c/c++ 数字转成字符串, 字符串转成数字 ------转帖 数字转字符串: 用C++的streanstream: #include <sstream> #Include <str ...

  2. spring依赖注入原理剖析

    PropertyDefinition.java package junit.test; public class PropertyDefinition { private String name; p ...

  3. 新手须知设计的法则 Mark

    经常看到一些讲如何学习设计的文章,坦白讲感觉有些千篇一律.且不痛不痒,都说要看点书.学点画.练软件.多观察……唉,练软件这事还要说么,难道你还需要告诉一个人学开发是需要学习编程语言的? 学习是基于过往 ...

  4. 转-sketch技巧

    10个帮你UI设计提速的Sketch使用技巧 2015-4-11 09:59| 发布者: yuanxingbbs| 查看: 1129| 评论: 0   选择使用Sketch的理由很多,因为好奇跟风安装 ...

  5. HDU-3874 Necklace 线段树+离线

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3874 比较简单的题,题意也好懂. 先O(n)求每个数左边第一次出现的与他相同的数的位置l[i].对询问 ...

  6. dom 关键字提示

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. openstack neutron 各节点网络配置

  8. 第二百一十一天 how can i 坚持

    参与感.做项目要有激情. 睡觉.

  9. hdu 4738 Caocao's Bridges(桥的最小权值+去重)

    http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:曹操有一些岛屿被桥连接,每座都有士兵把守,周瑜想把这些岛屿分成两部分,但他只能炸毁一条桥,问最少 ...

  10. centos下apache安装后无法访问

    2013.11.28遇到的问题: -------------------------------------- 一.centos下apache安装后无法访问 得查一下防火墙的问题 iptables添加 ...