REST接口GET方法获取文件保存到本地(C#)
生活随笔
收集整理的這篇文章主要介紹了
REST接口GET方法获取文件保存到本地(C#)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?REST接口GET方法獲取文件保存到本地(C#)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO;namespace testConsoleApplication1 {class Class1{static void Main(string[] args){string urlstr = @"http://127.0.0.1/open/files/***files";//string urlstr = @"http://127.0.0.1/open/files/***files/1.pdf";//"http://creditcard.bankcomm.com/jhbc/download/discount/baiwan_c3.pdf";//"http://127.0.0.1/open/files/***files/1.pdf";//FileStream fs = new FileStream(@"d:\***1.pdf", FileMode.Create, FileAccess.Write);FileStream fs = new FileStream(@"d:\filesList.xml", FileMode.Create, FileAccess.Write);Uri url = new Uri(urlstr);HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);myHttpWebRequest.Accept = "application/xml";myHttpWebRequest.Headers.Add("X-***-Token-Id","***"); myHttpWebRequest.Method = "GET";HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();Console.WriteLine(myHttpWebResponse.StatusCode.ToString());Stream receiveStream = myHttpWebResponse.GetResponseStream();Byte[] bytes = new Byte[100];int count = receiveStream.Read(bytes, 0, 100);while (count != 0){fs.Write(bytes, 0, count);count = receiveStream.Read(bytes, 0, 100);}fs.Close();receiveStream.Close();myHttpWebResponse.Close();}} }
?
轉載于:https://www.cnblogs.com/gitran/archive/2012/08/02/3644153.html
總結
以上是生活随笔為你收集整理的REST接口GET方法获取文件保存到本地(C#)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PowerDesigner逆向工程mys
- 下一篇: jquery实战-定宽(二)