English 中文(简体)
在互联网上,当我从服务器获得回复流时,我应当使用什么样的编码类型?
原标题:In .NET when I get a response stream from the server what type of encoding type should I use?

In the following example I m getting a response from the server; however do I need to set ASCII or UTF8 encoding type ?

Dim objURI As Uri = New Uri(URL)
Dim wReq As WebRequest = WebRequest.Create(objURI)
Dim wResp As WebResponse = wReq.GetResponse()
Dim respStream As Stream = wResp.GetResponseStream()
Dim reader As StreamReader = New StreamReader(respStream, Encoding.ASCII)
Dim respHTML As String = reader.ReadToEnd()
wResp.Close()
最佳回答
问题回答

这取决于您对服务器的期望。 就超文本而言(看来是您的期望),ASCII运行了99%的英文页时间,并允许你将所有超文本内容编码,而不管怎样。 然而,你应做的第一批事情之一是在文件标题中读到任何“金属”标签;这些内容将具体指明案文在体内的编码。 通常,如果这是ASCII,那么UTF-8就会落后于ASCII(但会显示出2-byte和4-byte的特性)。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签