MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Post data with NavigateWithWebResourceRequest and BasicAuthenticationRequested
@david-risney is already working on this.
Since Jun 30, 2022.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
I use webview2 to post some form variables with navigatewithwebresourcerequest to a page:
`Public Sub Navigate(urlString As String, PostData As List(Of SharedLib.ValuePair)) Implements iWebBrowser.Navigate
If mEdge.CoreWebView2 IsNot Nothing Then
Dim strFormData As String = ""
For Each itm In PostData
strFormData &= itm.id & "=" & System.Web.HttpUtility.UrlEncode(itm.value) & "&"
Next
If strFormData <> "" Then
strFormData = strFormData.Substring(0, strFormData.Length - 1)
Dim bytedata As Byte() = System.Text.Encoding.UTF8.GetBytes(strFormData)
Dim msPostData = New MemoryStream(bytedata.Length)
msPostData.Write(bytedata, 0, bytedata.Length)
msPostData.Seek(0, SeekOrigin.Begin)
Dim webResouceRequest = mEdge.CoreWebView2.Environment.CreateWebResourceRequest(urlString, "POST", msPostData, "Content-Type: application/x-www-form-urlencoded")
mEdge.CoreWebView2.NavigateWithWebResourceRequest(webResouceRequest)
Else
mEdge.Source = New Uri(urlString)
End If
Else
murlString = urlString
mPostData = PostData
End If
End Sub`
This works.
If I post those form variables to a site with basic authenttication, it will fail. My basic authentication is setup as follows:
`Public Sub SetCredentials(ServerAddress As String, User As String, Password As String) Implements iWebBrowser.SetCredentials
_ServerAddress = ServerAddress
_User = User
_Password = Password
'setup handler, if not already done
If _RequestFilterSet = False AndAlso mEdge.CoreWebView2 IsNot Nothing Then
AddHandler mEdge.CoreWebView2.BasicAuthenticationRequested, AddressOf BasicAuthenticationRequested
_RequestFilterSet = True
End If
End Sub
Private Sub BasicAuthenticationRequested(sender As Object, e As CoreWebView2BasicAuthenticationRequestedEventArgs)
If _ServerAddress <> "" AndAlso _User <> "" AndAlso _Password <> "" Then
'requested site must be our website, preventing pushing password to other websites
If e.Uri.ToLower.StartsWith(_ServerAddress.ToLower) Then
e.Response.UserName = _User
e.Response.Password = _Password
End If
End If
End Sub
`
The BasicAuthenticationRequested event is being triggered, but there are no form variables. Am I doing something wrong or is this a bug?
I solved it temporarily by disabling the basic authentication on the page, but this is not the solution.
Thanks
Paul
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.