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.

POST requests via TCefRequestRef no longer works..?

Post Reply
hvassbotn
Posts: 29
Joined: Tue Apr 25, 2017 3:02 pm
Location: Oslo, Norway
Contact:

POST requests via TCefRequestRef no longer works..?

Post by hvassbotn »

Upgraded to latest CEF and wrapper (3.3112.1649 = Chrome 60).

This code used to work with 3.3029.1604 (=Chrome 58):

Code: Select all

procedure TCEFBrowserForm.DoNavigate(const URL, PostData: string; ContentType: string);
var
  Header: ICefStringMultimap;
  Data: ICefPostData;
  Request: ICefRequest;
  PostDataElement: ICefPostDataElement;
  AnsiPostData: AnsiString;
  MappedURL: string;
begin
  if (Chromium.Browser = nil) or (Chromium.Browser.MainFrame = nil) then Exit; // Log error?
  MappedURL := Url;
  ReadyToNavigate(MappedURL, PostData, ContentType);
  if PostData <> '' then
  begin
    Request := TCefRequestRef.New;
    Request.Method := 'POST';
    Data := TCefPostDataRef.New;
    PostDataElement := TCefPostDataElementRef.New;
    AnsiPostData := AnsiString(PostData);
    PostDataElement.SetToBytes(Length(AnsiPostData), PAnsiChar(AnsiPostData));
    Data.AddElement(PostDataElement);
    Request.PostData := Data;
    Header := TCefStringMultimapOwn.Create;
    Header.Append('X-Infront-Terminal-Version', IntToStr(VersionNumber));
    if ContentType <> '' then
      Header.Append('Content-Type', ContentType);
    Request.SetHeaderMap(Header);
    Request.Url := MappedURL;
    Chromium.Browser.MainFrame.LoadRequest(Request);
  end
  else
  begin
    Chromium.LoadURL(MappedURL);
  end;
end;
But for some reason it no longer works. Nothing is loaded in the browser, and nothing is logged in debug.log

My code above is inspired by this sample:

https://stackoverflow.com/questions/129 ... h-chromium

Testing can be done using this service, for instance (described here http://httpbin.org/) :

Code: Select all

  BrowserWin.Navigate('http://httpbin.org/anything', 'PostData Sample', '');
TCPView from sysinternals shows that the process is not even opening any sockets during this call.

Removing the PostData parameter

Code: Select all

  BrowserWin.Navigate('http://httpbin.org/anything', '', '');
Triggers the normal LoadURL method, and generates a GET request as expected, with the result:

Code: Select all

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "en-US,en;q=0.8", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"
  }, 
  "json": null, 
  "method": "GET", 
  "origin": "*********", 
  "url": "http://httpbin.org/anything"
}
Are anyone else able to get POST requests working?
hvassbotn
Posts: 29
Joined: Tue Apr 25, 2017 3:02 pm
Location: Oslo, Norway
Contact:

Re: POST requests via TCefRequestRef no longer works..?

Post by hvassbotn »

I found the reason / workaround now.

I had turned off the DefaultURL (to improve performance and reduce flickering) from 'about:blank' to ''.

Commenting out that change, then the POST requests works again...

/H
Tomminger
Posts: 14
Joined: Mon Aug 27, 2018 8:22 pm
Location: Germany

Re: POST requests via TCefRequestRef no longer works..?

Post by Tomminger »

Hello,

I have disabled

// FDefaultUrl := 'about:blank';

in

uCEFChromiumCore

but it always send as

GET

and not as

POST

request.
Post Reply