I have created an application with .net Framework 4.8.1, it works well on the pc where it was developed (computer under windows 11) but has a different behavior on two other computers under windows 10 freshly installed and updated.
Part I = The context =
My application sends an http request with http2 to retrieve a token from a remote CloudFlare server.
Here is the request I send to the server:
{Method: POST, RequestUri: 'https://this.is.confidential/json/gov/v10/Api/CreateApiKey', Version: 2.0, Content: System.Net.Http.StringContent, Headers:
{
Content-Type: text/plain; charset=utf-8
}}
On the computer running Windows 11, the server response is as follows:
{StatusCode: 200, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:
{
Cache-Control: no-store, no-cache
Date: Tue, 13 Dec 2022 19:37:43 GMT
Server: cloudflare
Set-Cookie: __cf_bm=W5wDtxsixycI1_5G5fdgdfJGkVCX5nT9tzG8-1670960263-0-AfqDRz1MMF67L/ntDOShg3Jz3GZxMo/UtCYReTfDIJl1g0vQ/MfeVa5C8/PxQLtucWoYvV5nYGEyyuN/r19aWWo=; path=/; expires=Tue, 13-Dec-22 20:07:43 GMT; domain=.thisisconfidential.com; HttpOnly; Secure; SameSite=None
Vary: Accept-Encoding
access-control-allow-origin: *
x-duration: 33.200026
cf-cache-status: DYNAMIC
cf-ray: 779127ecadedf11c-CDG
Content-Type: application/json
}}
On the computer running Windows 10, the server response is as follows:
{StatusCode: 403, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:
{
Cache-Control: no-store, must-revalidate, no-cache, max-age=0, private, post-check=0, pre-check=0
Date: Tue, 13 Dec 2022 13:18:28 GMT
Server: cloudflare
Set-Cookie: __cf_bm=oKXtpXuiUmH5MeEA8n67RTG33dfZhv5Th5c3ZX0PAUSw1oA-1670937508-0-AX+aH9+MYxwNqOdbMZCmhg35ByjwgaTmtJdditJ7K1xEU1ex7au/PyiJ4JbCImQvICHQPcr+QJijZSeYfKme3/o=; path=/; expires=Tue, 13-Dec-22 13:48:28 GMT; domain=.thisisconfidential.com; HttpOnly; Secure; SameSite=None
x-frame-options: SAMEORIGIN
referrer-policy: same-origin
cf-ray: 778efc668ed6d07b-CDG
Content-Length: 16
Content-Type: text/plain; charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:01 GMT
}}
Part II = The code =
To use http2 in .NET 4.8.1 i use a HttpHandler custom class:
Imports System.Net.Http
Public Class Http2CustomHandler : Inherits WinHttpHandler
Protected Overrides Function SendAsync(request As HttpRequestMessage, cancellationToken As Threading.CancellationToken) As Task(Of HttpResponseMessage)
request.Version = New Version("2.0")
Return MyBase.SendAsync(request, cancellationToken)
End Function
End Class
And I call it when I send the request:
Using wclient As New HttpClient(New Http2CustomHandler())
Dim url As String = "https://this.is.confidential.com/json/gov/v10/Api/CreateApiKey"
With wclient
.BaseAddress = New Uri(url)
.DefaultRequestHeaders.UserAgent.Add(New Headers.ProductInfoHeaderValue("govAgent", "3.6.15"))
.DefaultRequestHeaders.Accept.Clear()
.DefaultRequestHeaders.Accept.Add(New Headers.MediaTypeWithQualityHeaderValue("text/plain"))
End With
Dim req = New HttpRequestMessage With {
.RequestUri = New Uri("https://this.is.confidential.com/json/gov/v10/Api/CreateApiKey"),
.Method = HttpMethod.Post,
.Content = New StringContent($"login={login}&password={password}&gov={gov}&long_life_token=true", Encoding.UTF8, "text/plain")
}
Dim response As HttpResponseMessage = Await wclient.SendAsync(req)
Dim jsonString = response.Content.ReadAsStringAsync().Result
Part III = some informations =
To launch my application on Windows 10 computers I copied the Release folder containing all the useful DLLs. I also published my code and installed my application on computers running Windows 10.
I also moved my VB net project on the other computers to test to compile and run and I have the same problem, the request fails systematically.
My windows 11 and 10 are up to date and have all .NET 4.8.1 installed.
I'm going crazy, I don't understand what the problem is.
Thank you.
UPDATE : There is actually a bug on windows 10 and .net framework 4.8/4.8.1 combined with WinHttpHandler. It does not work with 2.0 http version BUT if you put 3.0 http version it works with cloudflare WAF !! That's stupid !