Delphi用IdHTTP提交自定义Cookie
2011-03-06 22:08
337 查看
procedure Post_init;
begin
http.Request.SetHeaders;//必须加上,才能完成下面的工作
//http.Request.RawHeaders.Values['Cookie']:=_SESSION;//自定义Cookie
//http.Request.CustomHeaders.Values['Cookie']:=Cookie; //也得加上,不然Cookie没有意义,研究了很多
http.Http.Request.CustomHeaders.Text:='Cookie: '+Cookie;//最强悍的一个,上面两种方式有时候就是不行
http.HandleRedirects:= true;
http.Request.UserAgent := 'OS/1.0';//自定义客户端的签名,可以自定义
http.request.ContentType:='application/x-www-form-urlencoded';//使用POST方式提交时候,必须加上
http.Request.Referer :='http://www.test.cn/index.php';
http.Request.Host:=www.test.cn;
end;
下面同时对IdHttp的访问方式进行简单的说明,还是看代码吧:
function Post(AURL: string; const ASource: TStrings): string; overload;
function Post(AURL: string; const ASource: TStream): string; overload;
function Post(AURL: string; const ASource: TIdMultiPartFormDataStream): string; overload;
procedure Post(AURL: string; const ASource: TStrings; const AResponseContent: TStream); overload;
procedure Post(AURL: string; const ASource: TStream; const AResponseContent: TStream); overload;
procedure Post(AURL: string; const ASource: TIdMultiPartFormDataStream; AResponseContent: TStream); overload;
这是IdHttp进行POST方式的几个函数,就是几个参数:
第一个为URL值,第二个为本地传送的参数,第三个为服务器返回的参数(没有第三个函数的时候,返回的为服务器的参数)。
我们可以在第三个参数上面进行做文章,并可以做文件下载,读取web文件了。
get的方式如下:
procedure Get(AURL: string; const AResponseContent: TStream); overload;
function Get(AURL: string): string; overload;
参数和POST方式类型,但是没有第二个参数。
下面是IdHttp的相关例子:
HTTP.Post('http://www.test.cn/index.php',Params,ret);
showmessage(UTF8Decode(ret.DataString)); //UTF8编码的网页的代码
Cookie:='';
for i:=0 to Http.CookieManager.CookieCollection.Count -1 do
begin
if(Cookie='') then Cookie:=HTTP.CookieManager.CookieCollection[i].CookieText else Cookie:=_session+'; '+HTTP.CookieManager.CookieCollection.Items[i].ClientCookie;
end; //Cookie值获取
begin
http.Request.SetHeaders;//必须加上,才能完成下面的工作
//http.Request.RawHeaders.Values['Cookie']:=_SESSION;//自定义Cookie
//http.Request.CustomHeaders.Values['Cookie']:=Cookie; //也得加上,不然Cookie没有意义,研究了很多
http.Http.Request.CustomHeaders.Text:='Cookie: '+Cookie;//最强悍的一个,上面两种方式有时候就是不行
http.HandleRedirects:= true;
http.Request.UserAgent := 'OS/1.0';//自定义客户端的签名,可以自定义
http.request.ContentType:='application/x-www-form-urlencoded';//使用POST方式提交时候,必须加上
http.Request.Referer :='http://www.test.cn/index.php';
http.Request.Host:=www.test.cn;
end;
下面同时对IdHttp的访问方式进行简单的说明,还是看代码吧:
function Post(AURL: string; const ASource: TStrings): string; overload;
function Post(AURL: string; const ASource: TStream): string; overload;
function Post(AURL: string; const ASource: TIdMultiPartFormDataStream): string; overload;
procedure Post(AURL: string; const ASource: TStrings; const AResponseContent: TStream); overload;
procedure Post(AURL: string; const ASource: TStream; const AResponseContent: TStream); overload;
procedure Post(AURL: string; const ASource: TIdMultiPartFormDataStream; AResponseContent: TStream); overload;
这是IdHttp进行POST方式的几个函数,就是几个参数:
第一个为URL值,第二个为本地传送的参数,第三个为服务器返回的参数(没有第三个函数的时候,返回的为服务器的参数)。
我们可以在第三个参数上面进行做文章,并可以做文件下载,读取web文件了。
get的方式如下:
procedure Get(AURL: string; const AResponseContent: TStream); overload;
function Get(AURL: string): string; overload;
参数和POST方式类型,但是没有第二个参数。
下面是IdHttp的相关例子:
HTTP.Post('http://www.test.cn/index.php',Params,ret);
showmessage(UTF8Decode(ret.DataString)); //UTF8编码的网页的代码
Cookie:='';
for i:=0 to Http.CookieManager.CookieCollection.Count -1 do
begin
if(Cookie='') then Cookie:=HTTP.CookieManager.CookieCollection[i].CookieText else Cookie:=_session+'; '+HTTP.CookieManager.CookieCollection.Items[i].ClientCookie;
end; //Cookie值获取
相关文章推荐
- Delphi用IdHTTP提交自定义Cookie
- dephi中用idhttp提交cookie
- delphi使用IdHTTP模拟提交页面方法总结
- dephi中用idhttp提交cookie
- delphi使用IdHTTP模拟提交页面方法总结
- 如何用idhttp提交自己构造过的Cookie
- delphi使用IdHTTP模拟提交页面方法
- 用idhttp提交cookie
- dephi中用idhttp提交cookie
- delphi使用IdHTTP模拟提交页面方法总结
- dedecms织梦自定义表单提交之后如何发送到邮箱!
- delphi 自定义消息
- 织梦gbk版本中ajax提交自定义表单中文乱码问题解决方法
- 文件的上传+下载+表单的重复提交问题 +自定义拦截器:
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- 织梦dedecms自定义表单隐藏提交时间
- 自定义的token为什么没有写入cookie中?
- delphi 模拟POST提交数据
- 稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键
- Delphi完成网络页面表单数据地自动提交