'Problems with WebView2 NavigateWithWebResourceRequest

I made an WPF application (.NET framework) with a WebView2-Browser. This Browser window runs full screen in the app and should only open a single URL.

To get to the desired URL I tried to use.

webView.Source = new Uri("https://xxxx.com/")

This is working but I need to authorize myself on this website. Therefor I tried this:

var binFormatter = new BinaryFormatter();
var mStream = new MemoryStream();
binFormatter.Serialize(mStream, data);

//byte array.
mStream.ToArray();

var Content = "Authorization: Basic " + Convert.ToBase64String(
               System.Text.ASCIIEncoding.ASCII.GetBytes($"{authorization["USER"]}:{authorization["PW"]}"));

var request = webView.CoreWebView2.Environment.CreateWebResourceRequest(@"https://xxxxx.com/",
          "POST", mStream, Content);


webView.CoreWebView2.NavigateWithWebResourceRequest(request);
webView.CoreWebView2.WebResourceResponseReceived += ResponseRecieved;

But this neither navigates to the desired website nor authenticates myself on this site. Of course I know that Basic auth. is too weak and I need the website to accept this way of authorization.

May someone have an idea how to navigate and authenticate on the website using the WebView2 lib?

Thank you :) and have a great day :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source