Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General 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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2004, 05:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default Getting correct encoding from a webresponse

Hi guys,

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
WebRequest/WebResponse form submit problem. HELP! MAtkins ASP.NET 1.0 and 1.1 Professional 2 December 23rd, 2010 12:28 AM
encoding paarupalli J2EE 0 March 2nd, 2007 04:14 AM
Returning a custom WebResponse to the browser DudeBori82 ASP.NET 2.0 Professional 5 September 28th, 2006 07:53 AM
Webresponse contenttype different from request mikehsu317 C# 6 September 27th, 2006 10:42 AM
encoding alihussein3 Javascript How-To 1 October 28th, 2003 05:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.