- 使用什么字符编码
StreamReader.ReadToEnd()
? - 下面使用 (b) 而不是 (a) 的原因是什么?
- 如果使用(a)而不是(b),它们是否有成为字符编码问题的风险?
- 还有比(a)和(b)更好的方法吗?
(一个)
Dim strWebResponse As String
Dim Request As HttpWebRequest = WebRequest.Create(Url)
Using Response As WebResponse = smsRequest.GetResponse()
Using reader As StreamReader = New StreamReader(Response.GetResponseStream())
strWebResponse = reader.ReadToEnd()
End Using
End Using
(二)
Dim encoding As New UTF8Encoding()
Dim strWebResponse As String
Dim Request As HttpWebRequest = WebRequest.Create(Url)
Using Response As WebResponse = Request.GetResponse()
Dim responseBuffer(Response.ContentLength - 1) As Byte
Response.GetResponseStream().Read(responseBuffer, 0, Response.ContentLength - 1)
strWebResponse = encoding.GetString(responseBuffer)
End Using