使用 C# 中的 WebClient 下载 Csv 文件,但文件大小小于使用浏览器下载时 [英] Download Csv file with WebClient in C# but the size of file is less than when download with browser

查看:24
本文介绍了使用 C# 中的 WebClient 下载 Csv 文件,但文件大小小于使用浏览器下载时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回 csv 文件的链接.当我在浏览器(Chrome,Firefox,...)中打开它时,下载的文件大小为 86 KB,但是当我想使用以下代码下载它时,大小仅为 25 KB,而当我打开下载的文件时,它没有"t 有正确的数据(意味着没有列并且无法读取数据)

I have a link that return a csv file. When i open it in browser (Chrome,Firefox,...) the size of file that downloaded is 86 KB, but when i want to download it with below code size is just 25 KB and when i open the downloaded file it doesn't have correct data (means no columns and can't read data)

您可以在浏览器和代码中尝试

http://tsetmc.com/tsev2/data/Export-txt.aspx?t=i&a=1&b=0&i=43283802997035462

string url = "http://tsetmc.com/tsev2/data/Export-txt.aspx?t=i&a=1&b=0&i=43283802997035462";
 WebClient wc = new WebClient();
 wc.DownloadFile(url, "111.csv");

推荐答案

webClient 返回 zip 文件而不是纯文本/csv 文件我将 wc 输出文件扩展名更改为 zip 并且它正在工作...zip 将包含您在参数中指定的文件

webClient is returning you zip file instead of plain text /csv file I changed wc output file extension to zip and it is working... zip will contain file that you specified in argument

RestClient 截图

这篇关于使用 C# 中的 WebClient 下载 Csv 文件,但文件大小小于使用浏览器下载时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆