Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Method to count headers from web request?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading