MicrosoftEdge / MicrosoftEdge/WebView2Feedback
BasicAuthenticationRequired event removes Content-Type header from Request.
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Discussed in https://github.com/MicrosoftEdge/WebView2Feedback/discussions/4841
Originally posted by rpriest1260 September 30, 2024
Hello,
I am seeing an issue and wondering if this is a bug in the WebView2 code. Essentially, after the BasicAuthenticationRequested event fires and the credentials are supplied, the WebView2 code appears to remove the Content-Type header (if supplied), from the initial POST request sent. The webservice I intend to use needs that header, so this breaks the request. Should I file a bug for it? Has anyone else run into this?
Just to check I created the same POST request with a HttpWebRequest, object, and that does not have this problem - it does not strip the Content-Type header after the 407-Proxy Auth Required has been satisfied with the supplied credentials.
I am using:
- .NET 4.7.2
- WebView2 1.0.2792.45
- Proxy Server - with Proxy Authentication Required (I am testing with Fiddler Classic).
- A web service that accepts a POST request
My POST request is done as follows:
var postDataStream = new MemoryStream (Encoding.UTF8.GetBytes (PostData ?? ""));;
var request = webView.CoreWebView2.Environment.CreateWebResourceRequest(TargetUrl,
"POST", postDataStream, "Content-Type: application/x-www-form-urlencoded");
webView.CoreWebView2.NavigateWithWebResourceRequest(request);
And my credentials are supplied using the BasicAuthenticationRequired even, like so
webView.CoreWebView2.BasicAuthenticationRequested += (s, args) =>
{
//var creds = new {UserName="1", Password="1"};
var creds = (webProxy == null || string.IsNullOrEmpty(webProxy?.Address.ToString())) ? null : webProxy?.Credentials as NetworkCredential;
if (creds != null)
{
s_logger.Debug($"Setting proxy creds. User = {creds.UserName}");
args.Response.UserName = creds.UserName;
args.Response.Password = creds.Password;
}
};
And as mentioned, above, A basic HttpWebRequest, does not have this issue. If you would like to see what code I used to compare to WebView2, it looks like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
WebProxy myProxy = new WebProxy();
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address = new Uri("http://localhost:9191");
// Create a NetworkCredential object and associate it with the
// Proxy property of request object.
myProxy.Credentials = new NetworkCredential("1", "1");
request.Proxy = myProxy;
request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
request.ContentType = "application/x-www-form-urlencoded";
byte[] data = encoding.GetBytes("data1=postdatastring_fff");
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(data, 0, data.Length); // Send the data.
newStream.Close();
string text;
var response = (HttpWebResponse)request.GetResponse();
if any other information or sample code is needed, please just ask and I will supply.
Thank you in advance.
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.
Research direction
Start with the BasicAuthenticationRequested flow and the CreateWebResourceRequest and NavigateWithWebResourceRequest calls described in the report. Reproduce the proxy 407 scenario using the supplied POST and Content-Type, then compare the request before and after credentials are provided. Done means the Content-Type header remains present after authentication.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100