C# .Net using the http://requestb.in/ web API

RequestBin is an online service that provides a URL which collects web requests made to it and lets you inspect them online. It’s a useful way to take a look at what your Http client is sending. You can find RequestBin at requestb.in. Below is a code sample that allows you to connect from a C# console app.

using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace CsharpRequestBinDemo
{
    class CsharpRequestBinExample
    {
        static void Main()
        {
            var task = MakeRequest();
            task.Wait();

            var response = task.Result;
            var body = response.Content.ReadAsStringAsync().Result;
            Console.WriteLine(body);
        }

        private static Task<HttpResponseMessage> MakeRequest()
        {
            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Add("user-agent", "Console/4.5");
            return httpClient.GetAsync(new Uri("http://requestb.in/w06cjnw0"));
        }
    }
}

Returns: Ok

http://requestb.in
GET /w06cjnw0
 0 bytes 4s ago  
From [Your IP address..]
FORM/POST PARAMETERS

None
HEADERS

User-Agent: Console/4.5
Connection: close
Host: requestb.in
RAW BODY

None

Leave a Reply

Your email address will not be published. Required fields are marked *