首页 » 文章随笔 » 技巧教程 » delphi中dcef如何自定义referer信息?

delphi中dcef如何自定义referer信息?

TChromium自定义referer,在早期的dcef版本中,这样Append(‘Referer’,’http://www.bnwin.com’)就可以了,详细看下面代码,如果append不行,启用这句request.SetReferrer(request.url, REFERRER_POLICY_ALWAYS);

procedure TMainForm.chrm1BeforeResourceLoad(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame;
  const request: ICefRequest; const callback: ICefRequestCallback;
  out Result: TCefReturnValue);
var
  map: ICefStringMultimap;
  sAccept,sUserAgent:string;
begin      
    sAccept:= 'application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap,'+
    ' application/vnd.ms-xpsdocument, application/xaml+xml,text/html,application/octet-stream, */*';
    sUserAgent:='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36 QIHU 360EE';
  map := TCefStringMultimapOwn.Create;
  request.GetHeaderMap(map);
  map.Append('Referer',request.url);
  map.Append('Accept',sAccept);
  map.Append('User-Agent',sUserAgent);
 // ShowMessage(map.getvalue(1)+'  '+map.getkey(1));
  request.SetHeaderMap(map);
  //map:=nil;
 //request.SetReferrer(request.url, REFERRER_POLICY_ALWAYS);
end;

在高版本的dcef中自定义referer,可以直接定义request.

procedure TMainForm.ShowUrl(hurl,AllUrl:string);
var
 Request: ICefRequest;
 Data: ICefPostData;
 Header: ICefStringMultimap;
 sUserAgent:string;
begin
    if chrm1.Browser.IsLoading then chrm1.Browser.StopLoad;
    sUserAgent:='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36 QIHU 360EE';
    Request := TCefRequestRef.New;
    Request.SetReferrer(hurl,REFERRER_POLICY_ORIGIN);//定义referer
    Data := TCefPostDataRef.New;
    Header := TCefStringMultimapOwn.Create;
    Header.Append('Accept-Language', 'zh-CN');
    Header.Append('User-Agent',sUserAgent);
    Request.Assign(AllUrl,'POST',Data,header);

    chrm1.Browser.MainFrame.LoadRequest(Request);
end;

 

未经允许不得转载:百脑问 » delphi中dcef如何自定义referer信息?

×

感谢您的支持,我们会一直保持!

扫码支持
请土豪扫码随意打赏

打开微信扫一扫,即可进行扫码打赏哦

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

分享到:更多 ()

评论 抢沙发

评论前必须登录!