delphi IdHTTP中设置非标准头信息和读写cookie


本文整理自网络,侵删。

 for i:=0 to IdHTTP1.Response.RawHeaders.Count-1 do
  begin
    if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10))='SET-COOKIE' then
    begin
      sCookieTmp:=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT));
      sCookieTmp:=Copy(sCookieTmp,1,Pos(';',sCookieTmp)-1);
      sCookie:=sCookie+'; '+sCookieTmp;
    end;
  end;
 
  IdHTTP1:=TIdHTTP.Create(nil);
  try
  IdHTTP1.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52)';
  IdHTTP1.Request.Referer:='';
  IdHTTP1.Request.Accept:='*/*';
  IdHTTP1.Request.Connection:='Keep-Alive';
  IdHTTP1.Request.AcceptLanguage:='zh-cn';
  IdHTTP1.ReadTimeout:=30000;
  IdHTTP1.Request.CacheControl:='no-cache';
  IdHTTP1.Request.ContentType:='text/plain; charset=utf-8';
  IdHTTP1.HandleRedirects:=True;
  IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoKeepOrigProtocol];
  IdHTTP1.ProtocolVersion:=pv1_1;
 
  IdHTTP1.Request.CustomHeaders.Add('X-AjaxPro-Method: xhs');//设置非标准http头信息
  IdHTTP1.Request.CustomHeaders.Add('Cookie: '+sCookie);//设置cookie

  sPost:=TStringStream.Create('');
  try
    sPost.WriteString('');
    try
      sHtml:=IdHTTP1.Post('http://www.xxx.com',sPost);
    except
    end;
  finally
    sPost.Free;
  end;
  finally
    IdHTTP1.Free;
  end;

相关阅读 >>

Delphi 远程屏幕抓取的源代码

Delphi 获取局域网内的机器名

Delphi 不管什么datetime日期格式时间格式转换都不会错了

Delphi timagelist 中使用 透明 png 图标

Delphi idftp连接

Delphi windows 下用 Delphi 代码杀死进程,或者杀死自己

Delphi 两个非常有用的进程函数

Delphi 给 tcombobox 添加图标

Delphi intraweb 在iis下发布的web.config

Delphi 更改消息对话框中的按钮标题

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



打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...