Project Description

HttpLib makes it easier to asynchronously consume data from web services in C#. The library contains methods to upload files to server and get pages.

This project is designed for consuming existing web services. If you plan on writing a new http client/server application, it is recommended that you use WCF.

New Release - Now compatible with Windows Store applications http://jthorne.co.uk/blog/httplib/building-a-windows-store-class-library-for-httplib/

Supported Methods

  • GET
  • POST
  • PUT
  • HEAD
  • DELETE
  • Upload - PUT or POST

Samples

using Redslide.HttpLib

Get data from web service

Request.Get("http://jthorne.co.uk/", 
result=>
{
    Console.Write(result);
});

Download file from server

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 data to web service

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


Post data to web service and catch error

Request.Post("http://testing.local/post.php", new { name = "value"}, 
result=>
{
    Console.Write(result);
}, 
e=>
{
    Console.Write(e.ToString());
});


Upload file to server

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);
});

Changelog

Release 1.0.6

  • Compatible with Windows 8 Store Applications

Release 1.0.5


Release 1.0.4

  • Minor bug fixes
  • Fixed function naming/nomenclature

Last edited May 2 at 10:37 PM by Redslide, version 19