Is it possible to get data from web response in a right encoding

后端 未结 1 859
执笔经年
执笔经年 2020-12-11 12:29
using (WebResponse response = webRequest.GetResponse())
{       
    using (var reader = new StreamReader(response.GetResponseStream()))
    {
        string tmpStre         


        
相关标签:
1条回答
  • 2020-12-11 13:06
    // Get HTTP response. If this is not an HTTP response, you need to know the encoding yourself.
    using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse()) 
    {
        // If not an HTTP response, then response.CharacterSet must be replaced by a predefined encoding, e.g. UTF-8.
        using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet))) 
        {
            // Read whole stream to string.
            string tmpStreamData = reader.ReadToEnd(); 
            MessageBox.Show(tmpStreamData);
        }
    }
    
    0 讨论(0)
提交回复
热议问题