Page 1 of 1

Can not send referer

Posted: Tue Aug 18, 2020 10:45 am
by andreykrasnodar
I am using OLD version of CEF to run my program even on elder computers with Windows XP SP3
Trying to open new tab when user clicks on the link with target=blank.
The code with errirs is

Code: Select all

var
  Header: ICefStringMultimap;
  Request: ICefRequest;
  Data: ICefPostData;
  i: Integer;
  MainFrame : ICefFrame;
begin
  Request := TCefRequestRef.New;
  Request.Url := 'https://google.com';
  Request.Flags := [UR_FLAG_ALLOW_CACHED_CREDENTIALS];
  Request.Method := 'GET';    //or Request.setmethod('GET');
  Header := TCefStringMultimapOwn.Create;
  Header.Append('Referer', 'https://yandex.ru');
  Header.Append('Origin', 'https://yandex.ru');
  Request.SetHeaderMap(Header);
  Data := TCefPostDataRef.New;
  Request.SetPostData(Data);
  try
    MainFrame := Form1.Chromium2.Browser.GetMainFrame;
    MainFrame.LoadRequest(Request);
  except
    showmessage('Fail');
  end;
end;
I also tried this

Code: Select all

request.Assign('https://google.com','GET',Data,Header);
But there are 2 problems:
the little one is: sometimes application hangs
and the main problem is the Chromium does not send GET request. Some sites have security settings that not allow them to load them when request is not 'GET'.
When I use just

Code: Select all

.loadURL('https://example.com');
It sends GET request and when I use

Code: Select all

.LoadRequest(Request);
it does not.
To check it there is a simple code on PHP

Code: Select all

<?php
echo $_SERVER['REQUEST_METHOD'];
?>

Re: Problems with LoadRequest

Posted: Wed Aug 19, 2020 6:36 pm
by andreykrasnodar
Great! I have found it.

If I type

Code: Select all

  Data := TCefPostDataRef.New;
  Request.SetPostData(Data);
  Request.Method := 'GET';    //or Request.setmethod('GET');
The method is POST, but I can send referer and origin (and others) headers. If I do not set

Code: Select all

Request.SetPostData
The method is POST, but I can not send referer.
I need to send headers and request GET (both).

Re: Problems with LoadRequest

Posted: Wed Aug 19, 2020 6:59 pm
by andreykrasnodar
That code sends GET request and header referer. Great deal!
You should not insert any functions into this code (such as messageboxes, adding lines to TMemo and others) to prevent application hanging.