Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Examples

Arthur Heidt edited this page Nov 24, 2018 · 3 revisions

HttpReqSharp Examples

This example contains a few examples on how to use HttpReqSharp

GET Request Example

In this example a GET request is made to https://postman-echo.com/get, with one parameter foo, whose value is bar. Thus, the URL for this request would be https://postman-echo.com/get?foo=bar.

public static void Main(string[] args)
        {
            var baseUrl = "https://postman-echo.com/get";

            var parameterName = "foo";
            var parameterValue = "bar";

            // Create request handler
            var handler = new HttpRequestHandler();

            // Wrap parameter in a parameter object
            var param = new HttpRequestParameter(parameterName, parameterValue);

            // Put the parameters in a list. But you can use anything that implements the IEnumerable interface.
            var parameters = new List<IHttpRequestParameter>() { param };

            // Asynchronously make the request.
            var resultTask = handler.SendHttpRequestAsync(baseUrl, parameters, null, HttpRequestType.GET);

            // Do something with the results
            resultTask.ContinueWith(task => { Console.WriteLine(task.Result.ResponseBody); });

            Console.ReadLine();
        }

Output:

{"args":{"foo":"bar"},"headers":{"x-forwarded-proto":"https","host":"postman-echo.com","x-forwarded-port":"443"},"url":"https://postman-echo.com/get?foo=bar"}

Clone this wiki locally