RSS订阅 | 匿名投稿
您的位置:网站首页 > 组件 > 正文

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

作者:admin 来源: 日期:2017/3/28 23:12:56 人气: 标签:

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;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料