Using InternetHeaders

I have all kinds of strange behaviors with InternetHeaders: most of the time, some of the entries are not available in my application (at run time/download time).

When I check them using FireFox, these data are there.

I am starting to not have any more idea to know what really happens. *

Talk a bit about Content-Length:

If My_Headers.Value("Content-Length") <> "" Then L_Date.Text = "Content-Length:" TextField9.Text = My_Headers.Value("Content-Length") End If

That value is not displayed, but the server returns it when I call for the whole list of InternetHeaders.

At download time, I report the InternetHeaders in a GroupBox full of Labels and TextFields.
I also have a different window to decode the same InternetHeaders.

In that project, I use some of these properties (the file name for example), and sometimes, that header does not exists (is blank). I’ve made a specific test, and when I download - say 365 files - I get some of these and I do not know why.

Ideas ?

  • I will try to make the report in a Listbox(automatically, using Count in a loop…)

Listbox: no change, the Content-Length is empty.

Of course, for the report (log in a text file), I read the downloaded file size. I want to use that value to compare what I have vs what the server says the file is, but…

A browser may show the content if it has a User-Agent request header you may try that.

Or perhaps you get the response and request headers mixed up?

Used code:

[code] Dim Img_Headers As New HTTPSecureSocket
Dim My_Headers As InternetHeaders

My_Headers = Img_Headers.GetHeaders(Base_Img_URL, 30)
If My_Headers <> Nil Then[/code]

And I decode mY_Headers here.

I even set mY_Headers to Nil just in case… in my download loop my code do something strange…

I even checked the values in the debugger.

Also, I have another window with some dedicated (for debug) buttons; in one I decode the InternetHeaders.

With GetHeaders you’ll only request the headers. It’s making a call to the url but gives only headers.

Perhaps you might wanna try a different approach.
Using PageHeaders that will be set once you have made the request when it’s done.

You’ll need a GET request. GetHeaders might create a HEAD request sp the server responds differently perhaps.

And that is exactly what I want. I am lucky (here).

And in the Headrrs, I get the data I want, notaly Content-Length, Item name, etc.

Code from my project who report the InternetHeaders:

[code] // Set the Encoding as UTF8
Headers_Strings = ConvertEncoding(My_Headers.Source, Encodings.UTF8)

// Replace the line endings with EndOfLine
Headers_Strings = ReplaceLineEndings(Headers_Strings,EndOfLine)

// List test: Report the InternetHeaders in a ListBox:
LB_Headers.AddRow "Protocol", NthField(Headers_Strings, EndOfLine, 1) // Special case
LB_Headers.AddRow "Date:", My_Headers.Value("Date")
LB_Headers.AddRow "Server:", My_Headers.Value("Server")
LB_Headers.AddRow "X-Px:", My_Headers.Value("X-Px")
LB_Headers.AddRow "ETag:", My_Headers.Value("ETag")
LB_Headers.AddRow "Age:", My_Headers.Value("Age")
LB_Headers.AddRow "Cache-Control:", My_Headers.Value("Cache-Control")
LB_Headers.AddRow "Expires:", My_Headers.Value("Expires")
LB_Headers.AddRow "Content-Length:", My_Headers.Value("Content-Length")
LB_Headers.AddRow "Content-Type:", My_Headers.Value("Content-Type")
LB_Headers.AddRow "Content-Disposition:", My_Headers.Value("Content-Disposition")
LB_Headers.AddRow "Connection:", My_Headers.Value("Connection")[/code]

Column 0 is the Property name, Column 1 is the property Value; for example, Connection always get Close.

Nota: this project is specific to one server location (and the returned headers are meant to be unchanged).
Also, note the alternate use of AddRow.

I will get an eye to PageHeaders.
As far as I can see, HTTPSecureSocket.PageHeaders returns the same information (less Content-Length) I can get from HTTPSecureSocket.GetHeaders.

I displayed together (adn populated too) the InternetHeaders in a bunch of TextFields and in a Listbox. The Listbox (who was populated oafter the TextFields) appears to have data in the Content-Length entry.

So, I attempted a crazy test: I called five (yes, 5 times) the Method to get and display the InternetHeaders contents, and I get the Content-Length values !

I will remove them one after the other and stop to the needed times to get them complete.