Open Source code: HTTP Request Encapsulation Class Library Httplib Introduction, instructions for use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.