VB.NETGeneral VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I have the following code that retrieves a webpage.
My problem is getting it to use the right encoding.
I've tested it against a danish page, but it won't show the danish characters. When I set it to sniff the encoding (using
Code:
sr = New System.IO.StreamReader(strm, True)
) it sets it to UTF8, but when I browse the page using MSIE with auto-selection of encoding, it uses Western European (and displays the danish chars correctly).
Any ideas?
The code:
Code:
' Create a new WebRequest Object to the mentioned URL.
Dim myWebRequest As System.Net.WebRequest = System.Net.WebRequest.Create(txtUrl.Text)
' Set the 'Timeout' property in Milliseconds.
myWebRequest.Timeout = 10000
Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("Unicode")
' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As System.Net.WebResponse = myWebRequest.GetResponse()
Dim strm As System.IO.Stream
Dim sr As System.IO.StreamReader
Dim line As String
strm = myWebResponse.GetResponseStream()
sr = New System.IO.StreamReader(strm, True)
'sr = New System.IO.StreamReader(strm, encode)
MsgBox("Encoding: " & sr.CurrentEncoding.ToString)
txtSrc.Text = ""
Do
line = sr.ReadLine()
txtSrc.Text += line
Loop While Not line Is Nothing