Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Can not send referer

Post Reply
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Can not send referer

Post 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'];
?>
Last edited by andreykrasnodar on Thu Aug 20, 2020 8:15 pm, edited 1 time in total.
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Problems with LoadRequest

Post 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).
Last edited by andreykrasnodar on Thu Aug 20, 2020 8:15 am, edited 2 times in total.
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Problems with LoadRequest

Post 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.
Post Reply