開原始碼:Http請求封裝類庫HttpLib介紹、使用說明

來源:互聯網
上載者:User

標籤:com   nbsp   產生   原始碼下載   擷取資料   web服務   bug   開原始碼   for   

今天介紹一個很好用的Http請求類庫--Httplib。一直以來,我們都是為了一次web請求,單獨寫一段代碼

有了這個類,我們就可以很方便的直接使用了。

項目介紹:

http://www。suchso。com/UIweb/jquery-Plupload-use.html

基於C#語言,Httplib讓非同步互動處理資料更容易了。類庫的方法包括:上傳檔案到伺服器,擷取頁面資料。

該項目專門為web服務寫的,如果你打算重新寫一個http用戶端和服務端的話,建議你使用wcf。

最新代碼下載:http://jthorne.co.uk/blog/httplib/building-a-windows-store-class-library-for-httplib/

 

支援的方法有:
  • GET

  • POST

  • PUT

  • HEAD

  • DELETE

  • Upload - PUT or POST

用法:

引用dll

using Redslide.HttpLib

從web服務擷取資料
Request.Get("http://jthorne.co.uk/", result=>{    Console.Write(result);});

 

從伺服器下載資料
Request.Get("http://cachefly.cachefly.net/100mb.test", (headers, result) =>{        FileStream fs = new FileStream(@"C:\100mb.test", FileMode.OpenOrCreate);        result.CopyTo(fs);        fs.Close();});

 

Post資料給web服務
Request.Post("http://testing.local/post.php", new {name="james",username="Redslide"}, result=>{    Console.Write(result);});



Post資料給web服務,並且捕獲異常
Request.Post("http://testing.local/post.php", new { name = "value"}, result=>{    Console.Write(result);}, e=>{    Console.Write(e.ToString());});



上傳檔案到伺服器
Request.Upload("http://testing.local/post.php", new {name = "value"}, new[] {    new NamedFileStream("file", "photo.jpg", "image/jpeg", new FileStream(@"C:\photo.jpg",FileMode.Open))}, result=>{    Console.Write(result);});

用起來還是很簡單的。這樣分裝好的類庫,大大的減少了我們的工作量,並且因為有團隊維護和很好的異常處理,

減少bug的產生。當然你要是不放心,你可以閱讀原始碼,重新編譯。原始碼:http://httplib.codeplex.com/SourceControl/latest

開原始碼:Http請求封裝類庫HttpLib介紹、使用說明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.