I’m trying to download an HTML page to a local file. I’m using the HTTPSocket (see HTTPDownloader example). The downloaded page I’d like to show in a HTMLViewer. This is working fine.
If I load https://www.rentalcars.com/ar in the HTMLViewer, it loads fine even though is NOT in the HEAD of the page.
A downloaded version of the same page, does not contain this information either, obviously, but the downloaded file does NOT render correctly anymore.
I tested this with the Native and the WebKit rendering engine.
If I manually add to the HEAD, all is fine.
This triggers 2 questions:
Is there a way to force the HTML page to be encoded as UTF-8 in case it wouldn’t be UTF-8 while it gets downloaded?
Can I add the to the HEAD while the file is downloaded? If not, the only option I have is to open the HTML file, search for “” line and replace it with " to the HEAD"
I’m sure I’m not the first one running into this issue.
Can anyone help me with good advice, or with sample code that solved the problem for you?
Thanks Andrew, this solves one part of the problem. But I still have the issue that inside the downloaded HTML file the encoding is missing and therefor the HTMLViewer does not know how to render it. Do you know if there is a way to force the HTMLViewer to read and show the file correctly?
Derk, thank you for replying. Where should I request this?
I’m setting
DownloaderTarget.SetRequestHeader(“Content-Type:”, “text/html charset=utf-8”)
before I start the download, but this does not change the HEAD in the downloaded file and the HTMLviewer is still not showing the downloaded page correctly. Only the online page is show correctly (what is strange because the encoding info is also missing in the HEAD there…
The server is sending the encoding in the Content-Type header, but because you’re viewing a downloaded copy of the file there are no headers for the HTMLViewer to read. If you load the URL in the HTMLViewer directly then it displays correctly.