Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good low level http library for .Net [closed]

I'm looking for a library for .net, which would let me have full control over what gets sent via net. I'm going to use it for http experiments. I know of c#'s HttpWebRequest, and I want to try something different, because I cannot control all the headers (have you ever tried to change the case of Keep-Alive header that it sends?) or selectively ignore certificate errors. I want to experiment with this stuff. My language of choice is c#.

Can anybody recommend a good http library, which, would let me meddle with the low-level stuff when I want, but wouldn't burden me with it when I don't?

like image 320
Arsen Zahray Avatar asked Mar 10 '12 22:03

Arsen Zahray


1 Answers

I don't think you can beat the new Web Client which was released on Feb. 16th by Microsoft albeit in beta form. It's certainly ready for use in production. You can grab it via NuGet. The package is called System.Net.Http.

"This package provides a programming interface for modern HTTP application. The package includes HttpClient for sending requests over HTTP, as well as HttpRequestMessage and HttpResponseMessage."

The new HttpWebClient gives you full control of the response. You can add headers as easy as this:

        var response = new HttpResponseMessage<MyModel>(model, HttpStatusCode.Ok);
        response.Headers.Add("test", "test");

Here's a great introduction to the new HttpClient, http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee . Keep in mind this is the new HttpWebClient. I've used the old client and this is a real pleasure to use.

A quick update regarding licensing. The Web Api, and the HttpClient portion of it, support a “go-live” license that allows you to build and deploy production apps with it.

Update

Microsoft just posted some great HttpClient examples on CodePlex at http://aspnet.codeplex.com/SourceControl/list/changesets . If you're new to HttpClient check them out.

like image 114
Mark Avatar answered Oct 18 '22 08:10

Mark