I'm filling some headers and then use NavigateWithWebResourceRequest.
However in my project when I examine the headers at startNavigate, they're empty and the website opened is the one from the defaulturl, not the one i specified in the call.
What am I missing?
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.
NavigateWithWebResourceRequest loosing headers
NavigateWithWebResourceRequest loosing headers
You do not have the required permissions to view the files attached to this post.
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: NavigateWithWebResourceRequest loosing headers
Hi,
Please, download WebView4Delphi again and check the new feature in NavigateWithWebResourceRequestBrowser to send custom HTTP headers.
It uses a TCoreWebView2HttpRequestHeaders instance to set multiple headers.
Read the WebView2 documentation for CreateWebResourceRequest for more information :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environment2?view=webview2-1.0.1293.44#createwebresourcerequest
Please, download WebView4Delphi again and check the new feature in NavigateWithWebResourceRequestBrowser to send custom HTTP headers.
It uses a TCoreWebView2HttpRequestHeaders instance to set multiple headers.
Read the WebView2 documentation for CreateWebResourceRequest for more information :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environment2?view=webview2-1.0.1293.44#createwebresourcerequest
Re: NavigateWithWebResourceRequest loosing headers
Salvador,
thanks for your response.
I've downloaded the newest version. Deleted the component I had installed en re-installed the new version.
However in my project I still have the problem that in OnNavigateStarting the headers that were filled before the call to Navigate are empty.
thanks for your response.
I've downloaded the newest version. Deleted the component I had installed en re-installed the new version.
However in my project I still have the problem that in OnNavigateStarting the headers that were filled before the call to Navigate are empty.
You do not have the required permissions to view the files attached to this post.
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: NavigateWithWebResourceRequest loosing headers
Delete the WVBrowser1.DefaultURL property and remove the wvBrowser1.DefaultURL := url; line in the TForm.OnShow event.
DefaultURL will cause the browser to navigate to the DefaultURL address as soon as it's fully initialized and you want to call the "Navwithheader" function.
Delete the Navwithheader call from the TForm.OnShow and Timer1.OnTimer events and move it to WVBrowser1AfterCreated because the browser can only navigate after it has been initialized. The TWVBrowser.OnAfterCreated event is triggered when the browser is initialized and it's ready to accept commands.
You can use the interface directly but It's recommended to use the wrapper classes available in WebView4Delphi. For example :
DefaultURL will cause the browser to navigate to the DefaultURL address as soon as it's fully initialized and you want to call the "Navwithheader" function.
Delete the Navwithheader call from the TForm.OnShow and Timer1.OnTimer events and move it to WVBrowser1AfterCreated because the browser can only navigate after it has been initialized. The TWVBrowser.OnAfterCreated event is triggered when the browser is initialized and it's ready to accept commands.
You can use the interface directly but It's recommended to use the wrapper classes available in WebView4Delphi. For example :
Code: Select all
procedure TWebForm.WVBrowser1NavigationStarting(Sender: TObject;
const aWebView: ICoreWebView2;
const aArgs: ICoreWebView2NavigationStartingEventArgs);
var
TempArgs : TCoreWebView2NavigationStartingEventArgs;
TempHeaders : TCoreWebView2HttpRequestHeaders;
begin
TempArgs := TCoreWebView2NavigationStartingEventArgs.Create(aArgs);
TempHeaders := TCoreWebView2HttpRequestHeaders.Create(TempArgs.RequestHeaders);
FContenType := TempHeaders.GetHeader('Content-Type');
TempHeaders.Free;
TempArgs.Free;
end;
- salvadordf
- Posts: 4563
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: NavigateWithWebResourceRequest loosing headers
Use this URL for the tests :
You will be able to check what's really being sent in this page :
Or just use the NavigateWithWebResourceRequestBrowser demo and implement the TWVBrowser.OnNavigationStarting event to see the headers on a fully working demo.
Code: Select all
https://ptsv2.com/t/cef4delphi/post
Code: Select all
https://ptsv2.com/t/cef4delphi