I made a program in VB.net a few years back which counted headers from web requests and if it matched 10 it would do something else it would continue checking.
I’m now trying to transfer the program to C# and extend the program, does C# have a similar method? I found this but I am struggling to implement it.
For reference, this is my visual basic code:
Sub CheckLink(ByVal link As String)
Try
If link.Length >= 3 Then
Dim web As New WebClient
web.Headers.Add("user-agent", " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
Dim t As Byte() = WC.DownloadData("https://www.google.com")
Dim headers As WebHeaderCollection = WC.ResponseHeaders
WC.Dispose()
If headers.Count = 10 Then
Msgbox("Correct")
Else
// Do nothing
End If
End Try
End Sub
Is there a method for C#? thank you!
>Solution :
Why not use the WebHeaderCollection.Count property which gets the number of headers in the collection?
More info can be found here – https://docs.microsoft.com/en-us/dotnet/api/system.net.webheadercollection.count?view=net-6.0