public Task<HttpResponse> ExecuteAsStringAsync(HttpRequest request)
 {
     return Task.Factory.StartNew(() => ExecuteAsString(request));
 }
 public HttpResponse ExecuteAsString(HttpRequest request)
 {
     UniHttpRequest uniRequest = ConvertRequest(request);
     return ConvertResponse(uniRequest.asString());
 }
        private static UniHttpRequest ConvertRequest(HttpRequest request)
        {
            var uniMethod = ConvertHttpMethod(request.HttpMethod);
            var queryUrl = request.QueryUrl;

            //instantiate unirest request object
            UniHttpRequest uniRequest = new UniHttpRequest(uniMethod,queryUrl);

            //set request payload
            if (request.Body != null)
            {
                uniRequest.body(request.Body);
            }
            else if (request.FormParameters != null)
            {
                if (request.FormParameters.Any(p => p.Value is Stream || p.Value is FileStreamInfo))
                {
                    //multipart
                    foreach (var kvp in request.FormParameters)
                    {
                        if (kvp.Value is FileStreamInfo){
                            var fileInfo = (FileStreamInfo) kvp.Value;
                            uniRequest.field(kvp.Key,fileInfo.FileStream);
                            continue;
                        }
                        uniRequest.field(kvp.Key,kvp.Value);
                    }
                }
                else
                {
                    //URL Encode params
                    var paramsString = string.Join("&",
                        request.FormParameters.Select(kvp =>
                        string.Format("{0}={1}", Uri.EscapeDataString(kvp.Key), Uri.EscapeDataString(kvp.Value.ToString()))));
                    uniRequest.body(paramsString);
                    uniRequest.header("Content-Type", "application/x-www-form-urlencoded");

                }

            }

            //set request headers
            Dictionary<String, Object> headers = request.Headers.ToDictionary(item=> item.Key,item=> (Object) item.Value);
            uniRequest.headers(headers);

            //Set basic auth credentials if any
            if (!string.IsNullOrWhiteSpace(request.Username))
            {
                uniRequest.basicAuth(request.Username, request.Password);
            }
            return uniRequest;
        }
 public HttpResponse ExecuteAsBinary(HttpRequest request)
 {
     UniHttpRequest uniRequest = ConvertRequest(request);
     return ConvertResponse(uniRequest.asBinary());
 }
 public HttpContext(HttpRequest request, HttpResponse response)
 {
     Request = request;
     Response = response;
 }