Page 1 of 1
NavigateWithWebResourceRequest loosing headers
Posted: Fri Aug 12, 2022 9:49 am
by keessmit
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?
Re: NavigateWithWebResourceRequest loosing headers
Posted: Fri Aug 12, 2022 1:52 pm
by salvadordf
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
Re: NavigateWithWebResourceRequest loosing headers
Posted: Fri Aug 12, 2022 6:25 pm
by keessmit
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.
Re: NavigateWithWebResourceRequest loosing headers
Posted: Sat Aug 13, 2022 3:30 pm
by salvadordf
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 :
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;
Re: NavigateWithWebResourceRequest loosing headers
Posted: Sat Aug 13, 2022 3:34 pm
by salvadordf
Use this URL for the tests :
Code: Select all
https://ptsv2.com/t/cef4delphi/post
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.