请教各位大大C#中 GetResponseStream()返回什么编码的流。

本文介绍了一段C#代码,用于从指定URL下载网页内容并保存到本地文件。作者在使用不同编码方式保存文件时遇到了乱码问题,并寻求解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.IO;
using System.Net;

namespace Down

{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("pleases input the url:");
            string url=Console.ReadLine();


            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();


            Stream s = response.GetResponseStream();
            String line;
            StreamReader sr = new StreamReader(s);


            Console.WriteLine("where and which file do you want to place it ");
            string place = Console.ReadLine();
            StreamWriter sw = File.CreateText(place);


            while ((line = sr.ReadLine()) != null)
            {
                sw.WriteLine(line);
            }
            Console.WriteLine("the web is downloaded now!");


            sw.Close();
            sr.Close();


        }
            
         

           

        }
    }

当我File.CreateText("c://example.doc")后发现乱码了;

然后我又using System.Text 改了Unicode,UFT-8,UTF-7,ANSI,又Text.Encoding.GetEncoding N种字符都还是乱码。

求教各位大大。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值