Today introduces a very useful HTTP request Class library--httplib. All along, we've been writing a piece of code for a single Web request.
With this class, we can be very convenient to use directly.
Project Description:
http://www. Suchso. Com/uiweb/jquery-plupload-use.html
Based on the C # language, Httplib makes it easier to asynchronously interact with data. The methods of class library include uploading files to the server and getting the page data.
This project is written specifically for Web services, and it is recommended that you use WCF if you intend to re-write an HTTP client and server.
Latest code Download: http://jthorne.co.uk/blog/httplib/building-a-windows-store-class-library-for-httplib/
The supported methods are:
GET
POST
PUT
HEAD
DELETE
Upload-put or POST
Usage:
referencing DLLs
Using Redslide.httplib
Getting data from a Web service
Request.get ("http://jthorne.co.uk/", result=>{ console.write (result);});
Downloading data from the 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 the Web service
Request.post ("http://testing.local/post.php", new {name= "James", Username= "Redslide"}, result=>{ Console.Write (result);});
Post data to the Web service, and catch exceptions
Request.post ("http://testing.local/post.php", new {name = "value"}, result=>{ console.write (result);}, e=> { Console.Write (e.tostring ());});
Uploading files to the 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);});
It's still very simple to use. This kind of sub-assembly good library, greatly reduces our workload, and because of team maintenance and good exception handling,
Reduce the generation of bugs. Of course if you do not trust, you can read the source code, recompile. Source code: Http://httplib.codeplex.com/SourceControl/latest
Open Source code: HTTP Request Encapsulation Class Library Httplib Introduction, instructions for use