delphi的idhttp的get 和 post的使用

delphi的idhttp的get 和 post的使用

  4023人阅读  评论(1)  收藏  举报
  分类:
 
Delphi(146) 
[delphi]  view plain  copy
  1. function Tform1.IdHttpInit;  
  2. begin  
  3.   idhtp1.AllowCookies:=True;  
  4.   idhtp1.HTTPOptions:=[hoForceEncodeParams];  
  5.   idhtp1.ProtocolVersion:=pv1_1;  
  6.   idhtp1.Request.ContentType:='Content-Type=application/x-www-form-urlencoded; charset=UTF-8';  
  7.   idhtp1.Request.CacheControl:='no-cache';     
  8.   idhtp1.Request.UserAgent:='User-Agent=Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';  
  9.   idhtp1.Request.Accept:='Accept=*/*';  
  10.   idhtp1.Request.AcceptEncoding:='Accept-Encoding=gzip,deflate';  
  11.   idhtp1.Request.AcceptCharSet:='Accept-Charset=gb2312,utf-8;q=0.7,*;q=0.7';  
  12.   idhtp1.Request.Connection:='Connection=keep-alive';  
  13.   idhtp1.Request.Host:='Host=kyfw.12306.cn';  
  14.   idhtp1.Request.Referer:='https://kyfw.12306.cn/otn/login/init';  
  15.   idhtp1.Request.AcceptLanguage:='Accept-Language=zh-cn';  
  16.   Result:='';  
  17. end;  
  18.   
  19. function Tform1.GetCodeImg;  
  20. var url:string;  
  21. response:TMemoryStream;  
  22. jpg:TJPEGImage;  
  23. begin  
  24.   response:=TMemoryStream.Create;  
  25.    url:='https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&0.3110086616057921';  
  26.    idhtp1.Get(url,response);  
  27.    jpg:=TJPEGImage.Create;  
  28.    jpg.LoadFromStream(response);  
  29.    Result:='';  
  30. end;  
  31.   
  32. function Tform1.Login;  
  33. var  
  34.   url : string;  
  35.   Params:TStrings;  
  36. begin  
  37.   Params:=TStringList.Create;  
  38.   Params.Add('[email protected]');//用户名  
  39.   Params.Add('userDTO.password=xxxxxxx');//密码  
  40.   Params.Add('randCode=ku6a');//验证码  
  41.   Params.Add('randCode_validate=');  
  42.   Params.Add('OTcyNTU4=ZjIzYzc3MWJmMDk4OTk5YQ==');  
  43.   Params.Add('myversion=undefined');  
  44. end;  

你可能感兴趣的:(delphi的idhttp的get 和 post的使用)