如何使用restsharp下载文件 [英] How to use restsharp to download file

查看:697
本文介绍了如何使用restsharp下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个URL(来自客户端的实时供稿的URL),当我在浏览器中命中该URL时会返回xml响应.我已将其保存在8 MB的文本文件中.

I have a URL (URL for the live feed from client) which when I hit in browser returns the xml response . I have saved this in text file it`s size is 8 MB.

现在我的问题是我需要将此响应保存在服务器驱动器上的xml文件中.从那里,我将其插入数据库中.并且需要使用使用c#.net 4.5的http-client或rest-sharp库的代码发出请求

now my problem is that I need to save this response in xml file on server`s drive. from there I will insert this in database. and request needs to be made using code using http-client or rest-sharp library of c# .net 4.5

我不确定上述情况该怎么办.有人能给我一些建议吗

I am unsure what should I do for above case. can any body suggest me something

推荐答案

有了RestSharp,它就在自述文件:

With RestSharp, it's right there in the readme:

var client = new RestClient("http://example.com");
client.DownloadData(request).SaveAs(path);

对于HttpClient,它涉及的更多.看看

With HttpClient, it's a bit more involved. Have a look at this blog post.

另一个选择是 Flurl.Http (免责声明:我是作者).它在引擎盖下使用HttpClient并提供了流畅的界面和许多方便的辅助方法,包括:

Another option is Flurl.Http (disclaimer: I'm the author). It uses HttpClient under the hood and provides a fluent interface and lots of convenient helper methods, including:

await "http://example.com".DownloadFileAsync(folderPath, "foo.xml");

NuGet 上获取.

这篇关于如何使用restsharp下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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